Korean translation from Chang Hyun Park
[zxing.git] / csharp / SupportClass.cs
1 //\r
2 // In order to convert some functionality to Visual C#, the Java Language Conversion Assistant\r
3 // creates "support classes" that duplicate the original functionality.  \r
4 //\r
5 // Support classes replicate the functionality of the original code, but in some cases they are \r
6 // substantially different architecturally. Although every effort is made to preserve the \r
7 // original architecture of the application in the converted project, the user should be aware that \r
8 // the primary goal of these support classes is to replicate functionality, and that at times \r
9 // the architecture of the resulting solution may differ somewhat.\r
10 //\r
11 \r
12 using System;\r
13 \r
14 /// <summary>\r
15 /// Contains conversion support elements such as classes, interfaces and static methods.\r
16 /// </summary>\r
17 public class SupportClass\r
18 {\r
19         /// <summary>\r
20         /// Converts an array of sbytes to an array of bytes\r
21         /// </summary>\r
22         /// <param name="sbyteArray">The array of sbytes to be converted</param>\r
23         /// <returns>The new array of bytes</returns>\r
24         public static byte[] ToByteArray(sbyte[] sbyteArray)\r
25         {\r
26                 byte[] byteArray = null;\r
27 \r
28                 if (sbyteArray != null)\r
29                 {\r
30                         byteArray = new byte[sbyteArray.Length];\r
31                         for(int index=0; index < sbyteArray.Length; index++)\r
32                                 byteArray[index] = (byte) sbyteArray[index];\r
33                 }\r
34                 return byteArray;\r
35         }\r
36 \r
37         /// <summary>\r
38         /// Converts a string to an array of bytes\r
39         /// </summary>\r
40         /// <param name="sourceString">The string to be converted</param>\r
41         /// <returns>The new array of bytes</returns>\r
42         public static byte[] ToByteArray(System.String sourceString)\r
43         {\r
44                 return System.Text.UTF8Encoding.UTF8.GetBytes(sourceString);\r
45         }\r
46 \r
47         /// <summary>\r
48         /// Converts a array of object-type instances to a byte-type array.\r
49         /// </summary>\r
50         /// <param name="tempObjectArray">Array to convert.</param>\r
51         /// <returns>An array of byte type elements.</returns>\r
52         public static byte[] ToByteArray(System.Object[] tempObjectArray)\r
53         {\r
54                 byte[] byteArray = null;\r
55                 if (tempObjectArray != null)\r
56                 {\r
57                         byteArray = new byte[tempObjectArray.Length];\r
58                         for (int index = 0; index < tempObjectArray.Length; index++)\r
59                                 byteArray[index] = (byte)tempObjectArray[index];\r
60                 }\r
61                 return byteArray;\r
62         }\r
63 \r
64         /*******************************/\r
65         /// <summary>\r
66         /// Performs an unsigned bitwise right shift with the specified number\r
67         /// </summary>\r
68         /// <param name="number">Number to operate on</param>\r
69         /// <param name="bits">Ammount of bits to shift</param>\r
70         /// <returns>The resulting number from the shift operation</returns>\r
71         public static int URShift(int number, int bits)\r
72         {\r
73                 if ( number >= 0)\r
74                         return number >> bits;\r
75                 else\r
76                         return (number >> bits) + (2 << ~bits);\r
77         }\r
78 \r
79         /// <summary>\r
80         /// Performs an unsigned bitwise right shift with the specified number\r
81         /// </summary>\r
82         /// <param name="number">Number to operate on</param>\r
83         /// <param name="bits">Ammount of bits to shift</param>\r
84         /// <returns>The resulting number from the shift operation</returns>\r
85         public static int URShift(int number, long bits)\r
86         {\r
87                 return URShift(number, (int)bits);\r
88         }\r
89 \r
90         /// <summary>\r
91         /// Performs an unsigned bitwise right shift with the specified number\r
92         /// </summary>\r
93         /// <param name="number">Number to operate on</param>\r
94         /// <param name="bits">Ammount of bits to shift</param>\r
95         /// <returns>The resulting number from the shift operation</returns>\r
96         public static long URShift(long number, int bits)\r
97         {\r
98                 if ( number >= 0)\r
99                         return number >> bits;\r
100                 else\r
101                         return (number >> bits) + (2L << ~bits);\r
102         }\r
103 \r
104         /// <summary>\r
105         /// Performs an unsigned bitwise right shift with the specified number\r
106         /// </summary>\r
107         /// <param name="number">Number to operate on</param>\r
108         /// <param name="bits">Ammount of bits to shift</param>\r
109         /// <returns>The resulting number from the shift operation</returns>\r
110         public static long URShift(long number, long bits)\r
111         {\r
112                 return URShift(number, (int)bits);\r
113         }\r
114 \r
115         /*******************************/\r
116         /// <summary>\r
117         /// This method returns the literal value received\r
118         /// </summary>\r
119         /// <param name="literal">The literal to return</param>\r
120         /// <returns>The received value</returns>\r
121         public static long Identity(long literal)\r
122         {\r
123                 return literal;\r
124         }\r
125 \r
126         /// <summary>\r
127         /// This method returns the literal value received\r
128         /// </summary>\r
129         /// <param name="literal">The literal to return</param>\r
130         /// <returns>The received value</returns>\r
131         public static ulong Identity(ulong literal)\r
132         {\r
133                 return literal;\r
134         }\r
135 \r
136         /// <summary>\r
137         /// This method returns the literal value received\r
138         /// </summary>\r
139         /// <param name="literal">The literal to return</param>\r
140         /// <returns>The received value</returns>\r
141         public static float Identity(float literal)\r
142         {\r
143                 return literal;\r
144         }\r
145 \r
146         /// <summary>\r
147         /// This method returns the literal value received\r
148         /// </summary>\r
149         /// <param name="literal">The literal to return</param>\r
150         /// <returns>The received value</returns>\r
151         public static double Identity(double literal)\r
152         {\r
153                 return literal;\r
154         }\r
155 \r
156         /*******************************/\r
157         /// <summary>\r
158         /// Copies an array of chars obtained from a String into a specified array of chars\r
159         /// </summary>\r
160         /// <param name="sourceString">The String to get the chars from</param>\r
161         /// <param name="sourceStart">Position of the String to start getting the chars</param>\r
162         /// <param name="sourceEnd">Position of the String to end getting the chars</param>\r
163         /// <param name="destinationArray">Array to return the chars</param>\r
164         /// <param name="destinationStart">Position of the destination array of chars to start storing the chars</param>\r
165         /// <returns>An array of chars</returns>\r
166         public static void GetCharsFromString(System.String sourceString, int sourceStart, int sourceEnd, char[] destinationArray, int destinationStart)\r
167         {       \r
168                 int sourceCounter;\r
169                 int destinationCounter;\r
170                 sourceCounter = sourceStart;\r
171                 destinationCounter = destinationStart;\r
172                 while (sourceCounter < sourceEnd)\r
173                 {\r
174                         destinationArray[destinationCounter] = (char) sourceString[sourceCounter];\r
175                         sourceCounter++;\r
176                         destinationCounter++;\r
177                 }\r
178         }\r
179 \r
180         /*******************************/\r
181         /// <summary>\r
182         /// Sets the capacity for the specified ArrayList\r
183         /// </summary>\r
184         /// <param name="vector">The ArrayList which capacity will be set</param>\r
185         /// <param name="newCapacity">The new capacity value</param>\r
186         public static void SetCapacity(System.Collections.ArrayList vector, int newCapacity)\r
187         {\r
188                 if (newCapacity > vector.Count)\r
189                         vector.AddRange(new Array[newCapacity-vector.Count]);\r
190                 else if (newCapacity < vector.Count)\r
191                         vector.RemoveRange(newCapacity, vector.Count - newCapacity);\r
192                 vector.Capacity = newCapacity;\r
193         }\r
194 \r
195 \r
196 \r
197         /*******************************/\r
198         /// <summary>\r
199         /// Receives a byte array and returns it transformed in an sbyte array\r
200         /// </summary>\r
201         /// <param name="byteArray">Byte array to process</param>\r
202         /// <returns>The transformed array</returns>\r
203         public static sbyte[] ToSByteArray(byte[] byteArray)\r
204         {\r
205                 sbyte[] sbyteArray = null;\r
206                 if (byteArray != null)\r
207                 {\r
208                         sbyteArray = new sbyte[byteArray.Length];\r
209                         for(int index=0; index < byteArray.Length; index++)\r
210                                 sbyteArray[index] = (sbyte) byteArray[index];\r
211                 }\r
212                 return sbyteArray;\r
213         }\r
214 \r
215 }\r