New C# port from Suraj Supekar
[zxing.git] / csharp / common / CharacterSetECI.cs
diff --git a/csharp/common/CharacterSetECI.cs b/csharp/common/CharacterSetECI.cs
new file mode 100755 (executable)
index 0000000..54b8b98
--- /dev/null
@@ -0,0 +1,126 @@
+/*\r
+* Copyright 2008 ZXing authors\r
+*\r
+* Licensed under the Apache License, Version 2.0 (the "License");\r
+* you may not use this file except in compliance with the License.\r
+* You may obtain a copy of the License at\r
+*\r
+*      http://www.apache.org/licenses/LICENSE-2.0\r
+*\r
+* Unless required by applicable law or agreed to in writing, software\r
+* distributed under the License is distributed on an "AS IS" BASIS,\r
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+* See the License for the specific language governing permissions and\r
+* limitations under the License.\r
+*/\r
+using System;\r
+namespace com.google.zxing.common\r
+{\r
+       \r
+       /// <summary> Encapsulates a Character Set ECI, according to "Extended Channel Interpretations" 5.3.1.1\r
+       /// of ISO 18004.\r
+       /// \r
+       /// </summary>\r
+       /// <author>  Sean Owen\r
+       /// </author>\r
+       /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source \r
+       /// </author>\r
+       public sealed class CharacterSetECI:ECI\r
+       {\r
+               public System.String EncodingName\r
+               {\r
+                       get\r
+                       {\r
+                               return encodingName;\r
+                       }\r
+                       \r
+               }\r
+               \r
+               private static System.Collections.Hashtable VALUE_TO_ECI;\r
+               private static System.Collections.Hashtable NAME_TO_ECI;\r
+               \r
+               private static void  initialize()\r
+               {\r
+                       VALUE_TO_ECI = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable(29));\r
+                       NAME_TO_ECI = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable(29));\r
+                       // TODO figure out if these values are even right!\r
+                       addCharacterSet(0, "Cp437");\r
+                       addCharacterSet(1, new System.String[]{"ISO8859_1", "ISO-8859-1"});\r
+                       addCharacterSet(2, "Cp437");\r
+                       addCharacterSet(3, new System.String[]{"ISO8859_1", "ISO-8859-1"});\r
+                       addCharacterSet(4, "ISO8859_2");\r
+                       addCharacterSet(5, "ISO8859_3");\r
+                       addCharacterSet(6, "ISO8859_4");\r
+                       addCharacterSet(7, "ISO8859_5");\r
+                       addCharacterSet(8, "ISO8859_6");\r
+                       addCharacterSet(9, "ISO8859_7");\r
+                       addCharacterSet(10, "ISO8859_8");\r
+                       addCharacterSet(11, "ISO8859_9");\r
+                       addCharacterSet(12, "ISO8859_10");\r
+                       addCharacterSet(13, "ISO8859_11");\r
+                       addCharacterSet(15, "ISO8859_13");\r
+                       addCharacterSet(16, "ISO8859_14");\r
+                       addCharacterSet(17, "ISO8859_15");\r
+                       addCharacterSet(18, "ISO8859_16");\r
+                       addCharacterSet(20, new System.String[]{"SJIS", "Shift_JIS"});\r
+               }\r
+               \r
+               //UPGRADE_NOTE: Final was removed from the declaration of 'encodingName '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
+               private System.String encodingName;\r
+               \r
+               private CharacterSetECI(int value_Renamed, System.String encodingName):base(value_Renamed)\r
+               {\r
+                       this.encodingName = encodingName;\r
+               }\r
+               \r
+               private static void  addCharacterSet(int value_Renamed, System.String encodingName)\r
+               {\r
+                       CharacterSetECI eci = new CharacterSetECI(value_Renamed, encodingName);\r
+                       VALUE_TO_ECI[(System.Int32) value_Renamed] = eci; // can't use valueOf\r
+                       NAME_TO_ECI[encodingName] = eci;\r
+               }\r
+               \r
+               private static void  addCharacterSet(int value_Renamed, System.String[] encodingNames)\r
+               {\r
+                       CharacterSetECI eci = new CharacterSetECI(value_Renamed, encodingNames[0]);\r
+                       VALUE_TO_ECI[(System.Int32) value_Renamed] = eci; // can't use valueOf\r
+                       for (int i = 0; i < encodingNames.Length; i++)\r
+                       {\r
+                               NAME_TO_ECI[encodingNames[i]] = eci;\r
+                       }\r
+               }\r
+               \r
+               /// <param name="value">character set ECI value\r
+               /// </param>\r
+               /// <returns> {@link CharacterSetECI} representing ECI of given value, or null if it is legal but\r
+               /// unsupported\r
+               /// </returns>\r
+               /// <throws>  IllegalArgumentException if ECI value is invalid </throws>\r
+               public static CharacterSetECI getCharacterSetECIByValue(int value_Renamed)\r
+               {\r
+                       if (VALUE_TO_ECI == null)\r
+                       {\r
+                               initialize();\r
+                       }\r
+                       if (value_Renamed < 0 || value_Renamed >= 900)\r
+                       {\r
+                               throw new System.ArgumentException("Bad ECI value: " + value_Renamed);\r
+                       }\r
+                       return (CharacterSetECI) VALUE_TO_ECI[(System.Int32) value_Renamed];\r
+               }\r
+               \r
+               /// <param name="name">character set ECI encoding name\r
+               /// </param>\r
+               /// <returns> {@link CharacterSetECI} representing ECI for character encoding, or null if it is legal\r
+               /// but unsupported\r
+               /// </returns>\r
+               public static CharacterSetECI getCharacterSetECIByName(System.String name)\r
+               {\r
+                       if (NAME_TO_ECI == null)\r
+                       {\r
+                               initialize();\r
+                       }\r
+                       return (CharacterSetECI) NAME_TO_ECI[name];\r
+               }\r
+       }\r
+}
\ No newline at end of file