UTF7Encoding.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. /*
  2. * UTF7Encoding.cs - Implementation of the
  3. * "System.Text.UTF7Encoding" class.
  4. *
  5. * Copyright (c) 2002 Southern Storm Software, Pty Ltd
  6. * Copyright (c) 2003, 2004, Novell, Inc.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining
  9. * a copy of this software and associated documentation files (the "Software"),
  10. * to deal in the Software without restriction, including without limitation
  11. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12. * and/or sell copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included
  16. * in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  21. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  22. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  23. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  24. * OTHER DEALINGS IN THE SOFTWARE.
  25. */
  26. namespace System.Text
  27. {
  28. using System;
  29. [Serializable]
  30. [MonoTODO ("Fix serialization compatibility with MS.NET")]
  31. #if ECMA_COMPAT
  32. internal
  33. #else
  34. public
  35. #endif
  36. class UTF7Encoding : Encoding
  37. {
  38. // Magic number used by Windows for UTF-7.
  39. internal const int UTF7_CODE_PAGE = 65000;
  40. // Internal state.
  41. private bool allowOptionals;
  42. // Encoding rule table for 0x00-0x7F.
  43. // 0 - full encode, 1 - direct, 2 - optional, 3 - encode plus.
  44. private static readonly byte[] encodingRules = {
  45. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, // 00
  46. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 10
  47. 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 2, 3, 1, 1, 1, 1, // 20
  48. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 1, // 30
  49. 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 40
  50. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, 2, 2, 2, // 50
  51. 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 60
  52. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 0, 0, // 70
  53. };
  54. // Characters to use to encode 6-bit values in base64.
  55. private const String base64Chars =
  56. "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  57. // Map bytes in base64 to 6-bit values.
  58. private static readonly sbyte[] base64Values = {
  59. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 00
  60. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 10
  61. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, 63, // 20
  62. 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, // 30
  63. -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 40
  64. 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, // 50
  65. -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // 60
  66. 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, // 70
  67. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 80
  68. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 90
  69. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // A0
  70. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // B0
  71. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // C0
  72. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // D0
  73. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // E0
  74. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // F0
  75. };
  76. // Constructors.
  77. public UTF7Encoding ()
  78. : this (false)
  79. {
  80. }
  81. public UTF7Encoding (bool allowOptionals)
  82. : base (UTF7_CODE_PAGE)
  83. {
  84. this.allowOptionals = allowOptionals;
  85. body_name = "utf-7";
  86. encoding_name = "Unicode (UTF-7)";
  87. header_name = "utf-7";
  88. is_mail_news_display = true;
  89. is_mail_news_save = true;
  90. web_name = "utf-7";
  91. windows_code_page = UnicodeEncoding.UNICODE_CODE_PAGE;
  92. }
  93. // Internal version of "GetByteCount" that can handle
  94. // a rolling state between calls.
  95. private static int InternalGetByteCount
  96. (char[] chars, int index, int count, bool flush,
  97. int leftOver, bool allowOptionals)
  98. {
  99. // Validate the parameters.
  100. if (chars == null) {
  101. throw new ArgumentNullException ("chars");
  102. }
  103. if (index < 0 || index > chars.Length) {
  104. throw new ArgumentOutOfRangeException ("index", _("ArgRange_Array"));
  105. }
  106. if (count < 0 || count > (chars.Length - index)) {
  107. throw new ArgumentOutOfRangeException ("count", _("ArgRange_Array"));
  108. }
  109. // Determine the length of the output.
  110. int length = 0;
  111. int leftOverSize = (leftOver >> 8);
  112. byte[] rules = encodingRules;
  113. int ch, rule;
  114. while (count > 0) {
  115. ch = (int)(chars[index++]);
  116. --count;
  117. if (ch < 0x0080) {
  118. rule = rules[ch];
  119. } else {
  120. rule = 0;
  121. }
  122. switch (rule) {
  123. case 0:
  124. // Handle characters that must be fully encoded.
  125. if (leftOverSize == 0) {
  126. ++length;
  127. }
  128. leftOverSize += 16;
  129. while (leftOverSize >= 6) {
  130. ++length;
  131. leftOverSize -= 6;
  132. }
  133. break;
  134. case 1:
  135. // The character is encoded as itself.
  136. if (leftOverSize != 0) {
  137. // Flush the previous encoded sequence.
  138. length += 2;
  139. leftOverSize = 0;
  140. }
  141. ++length;
  142. break;
  143. case 2:
  144. // The character may need to be encoded.
  145. if (allowOptionals) {
  146. goto case 1;
  147. } else {
  148. goto case 0;
  149. }
  150. // Not reached.
  151. case 3:
  152. // Encode the plus sign as "+-".
  153. if (leftOverSize != 0) {
  154. // Flush the previous encoded sequence.
  155. length += 2;
  156. leftOverSize = 0;
  157. }
  158. length += 2;
  159. break;
  160. }
  161. }
  162. if (leftOverSize != 0 && flush) {
  163. length += 2;
  164. }
  165. // Return the length to the caller.
  166. return length;
  167. }
  168. // Get the number of bytes needed to encode a character buffer.
  169. public override int GetByteCount (char[] chars, int index, int count)
  170. {
  171. return InternalGetByteCount (chars, index, count, true, 0, allowOptionals);
  172. }
  173. // Internal version of "GetBytes" that can handle a
  174. // rolling state between calls.
  175. private static int InternalGetBytes
  176. (char[] chars, int charIndex, int charCount,
  177. byte[] bytes, int byteIndex, bool flush,
  178. ref int leftOver, bool allowOptionals)
  179. {
  180. // Validate the parameters.
  181. if (chars == null) {
  182. throw new ArgumentNullException ("chars");
  183. }
  184. if (bytes == null) {
  185. throw new ArgumentNullException ("bytes");
  186. }
  187. if (charIndex < 0 || charIndex > chars.Length) {
  188. throw new ArgumentOutOfRangeException ("charIndex", _("ArgRange_Array"));
  189. }
  190. if (charCount < 0 || charCount > (chars.Length - charIndex)) {
  191. throw new ArgumentOutOfRangeException ("charCount", _("ArgRange_Array"));
  192. }
  193. if (byteIndex < 0 || byteIndex > bytes.Length) {
  194. throw new ArgumentOutOfRangeException ("byteIndex", _("ArgRange_Array"));
  195. }
  196. // Convert the characters.
  197. int posn = byteIndex;
  198. int byteLength = bytes.Length;
  199. int leftOverSize = (leftOver >> 8);
  200. int leftOverBits = (leftOver & 0xFF);
  201. byte[] rules = encodingRules;
  202. String base64 = base64Chars;
  203. int ch, rule;
  204. while (charCount > 0) {
  205. ch = (int)(chars[charIndex++]);
  206. --charCount;
  207. if (ch < 0x0080) {
  208. rule = rules[ch];
  209. } else {
  210. rule = 0;
  211. }
  212. switch (rule) {
  213. case 0:
  214. // Handle characters that must be fully encoded.
  215. if (leftOverSize == 0) {
  216. if (posn >= byteLength) {
  217. throw new ArgumentException (_("Arg_InsufficientSpace"), "bytes");
  218. }
  219. bytes[posn++] = (byte)'+';
  220. }
  221. leftOverBits = ((leftOverBits << 16) | ch);
  222. leftOverSize += 16;
  223. while (leftOverSize >= 6) {
  224. if (posn >= byteLength) {
  225. throw new ArgumentException (_("Arg_InsufficientSpace"), "bytes");
  226. }
  227. leftOverSize -= 6;
  228. bytes[posn++] = (byte)(base64 [leftOverBits >> leftOverSize]);
  229. leftOverBits &= ((1 << leftOverSize) - 1);
  230. }
  231. break;
  232. case 1:
  233. // The character is encoded as itself.
  234. if (leftOverSize != 0) {
  235. // Flush the previous encoded sequence.
  236. if ((posn + 2) > byteLength) {
  237. throw new ArgumentException (_("Arg_InsufficientSpace"), "bytes");
  238. }
  239. bytes[posn++] = (byte)(base64 [leftOverBits << (6 - leftOverSize)]);
  240. bytes[posn++] = (byte)'-';
  241. leftOverSize = 0;
  242. leftOverBits = 0;
  243. }
  244. if (posn >= byteLength) {
  245. throw new ArgumentException (_("Arg_InsufficientSpace"), "bytes");
  246. }
  247. bytes[posn++] = (byte)ch;
  248. break;
  249. case 2:
  250. // The character may need to be encoded.
  251. if (allowOptionals) {
  252. goto case 1;
  253. } else {
  254. goto case 0;
  255. }
  256. // Not reached.
  257. case 3:
  258. // Encode the plus sign as "+-".
  259. if (leftOverSize != 0) {
  260. // Flush the previous encoded sequence.
  261. if ((posn + 2) > byteLength) {
  262. throw new ArgumentException (_("Arg_InsufficientSpace"), "bytes");
  263. }
  264. bytes[posn++] = (byte)(base64 [leftOverBits << (6 - leftOverSize)]);
  265. bytes[posn++] = (byte)'-';
  266. leftOverSize = 0;
  267. leftOverBits = 0;
  268. }
  269. if ((posn + 2) > byteLength) {
  270. throw new ArgumentException (_("Arg_InsufficientSpace"), "bytes");
  271. }
  272. bytes[posn++] = (byte)'+';
  273. bytes[posn++] = (byte)'-';
  274. break;
  275. }
  276. }
  277. if (leftOverSize != 0 && flush) {
  278. if ((posn + 2) > byteLength) {
  279. throw new ArgumentException (_("Arg_InsufficientSpace"), "bytes");
  280. }
  281. bytes[posn++] = (byte)(base64 [leftOverBits << (6 - leftOverSize)]);
  282. bytes[posn++] = (byte)'-';
  283. leftOverSize = 0;
  284. leftOverBits = 0;
  285. }
  286. leftOver = ((leftOverSize << 8) | leftOverBits);
  287. // Return the length to the caller.
  288. return posn - byteIndex;
  289. }
  290. // Get the bytes that result from encoding a character buffer.
  291. public override int GetBytes (char[] chars, int charIndex, int charCount,
  292. byte[] bytes, int byteIndex)
  293. {
  294. int leftOver = 0;
  295. return InternalGetBytes (chars, charIndex, charCount, bytes, byteIndex, true,
  296. ref leftOver, allowOptionals);
  297. }
  298. // Internal version of "GetCharCount" that can handle
  299. // a rolling state between call.s
  300. private static int InternalGetCharCount
  301. (byte[] bytes, int index, int count, int leftOver)
  302. {
  303. // Validate the parameters.
  304. if (bytes == null) {
  305. throw new ArgumentNullException ("bytes");
  306. }
  307. if (index < 0 || index > bytes.Length) {
  308. throw new ArgumentOutOfRangeException ("index", _("ArgRange_Array"));
  309. }
  310. if (count < 0 || count > (bytes.Length - index)) {
  311. throw new ArgumentOutOfRangeException ("count", _("ArgRange_Array"));
  312. }
  313. // Determine the length of the result.
  314. int length = 0;
  315. int byteval;
  316. bool normal = ((leftOver & 0x01000000) == 0);
  317. bool prevIsPlus = ((leftOver & 0x02000000) != 0);
  318. int leftOverSize = ((leftOver >> 16) & 0xFF);
  319. sbyte[] base64 = base64Values;
  320. while (count > 0) {
  321. byteval = (int)(bytes[index++]);
  322. --count;
  323. if (normal) {
  324. if (byteval != '+') {
  325. // Directly-encoded character.
  326. ++length;
  327. } else {
  328. // Start of a base64-encoded character.
  329. normal = false;
  330. prevIsPlus = true;
  331. }
  332. } else {
  333. // Process the next byte in a base64 sequence.
  334. if (byteval == (int)'-') {
  335. // End of a base64 sequence.
  336. if (prevIsPlus) {
  337. ++length;
  338. leftOverSize = 0;
  339. }
  340. normal = true;
  341. } else if (base64 [byteval] != -1) {
  342. // Extra character in a base64 sequence.
  343. leftOverSize += 6;
  344. if (leftOverSize >= 16) {
  345. ++length;
  346. leftOverSize -= 16;
  347. }
  348. } else {
  349. // Normal character terminating a base64 sequence.
  350. if (leftOverSize > 0) {
  351. ++length;
  352. leftOverSize = 0;
  353. }
  354. ++length;
  355. normal = true;
  356. }
  357. prevIsPlus = false;
  358. }
  359. }
  360. // Return the final length to the caller.
  361. return length;
  362. }
  363. // Get the number of characters needed to decode a byte buffer.
  364. public override int GetCharCount (byte[] bytes, int index, int count)
  365. {
  366. return InternalGetCharCount (bytes, index, count, 0);
  367. }
  368. // Internal version of "GetChars" that can handle a
  369. // rolling state between calls.
  370. private static int InternalGetChars (byte[] bytes, int byteIndex, int byteCount,
  371. char[] chars, int charIndex, ref int leftOver)
  372. {
  373. // Validate the parameters.
  374. if (bytes == null) {
  375. throw new ArgumentNullException ("bytes");
  376. }
  377. if (chars == null) {
  378. throw new ArgumentNullException ("chars");
  379. }
  380. if (byteIndex < 0 || byteIndex > bytes.Length) {
  381. throw new ArgumentOutOfRangeException ("byteIndex", _("ArgRange_Array"));
  382. }
  383. if (byteCount < 0 || byteCount > (bytes.Length - byteIndex)) {
  384. throw new ArgumentOutOfRangeException ("byteCount", _("ArgRange_Array"));
  385. }
  386. if (charIndex < 0 || charIndex > chars.Length) {
  387. throw new ArgumentOutOfRangeException ("charIndex", _("ArgRange_Array"));
  388. }
  389. // Convert the bytes into characters.
  390. int posn = charIndex;
  391. int charLength = chars.Length;
  392. int byteval, b64value;
  393. bool normal = ((leftOver & 0x01000000) == 0);
  394. bool prevIsPlus = ((leftOver & 0x02000000) != 0);
  395. int leftOverSize = ((leftOver >> 16) & 0xFF);
  396. int leftOverBits = (leftOver & 0xFFFF);
  397. sbyte[] base64 = base64Values;
  398. while (byteCount > 0) {
  399. byteval = (int)(bytes[byteIndex++]);
  400. --byteCount;
  401. if (normal) {
  402. if (byteval != '+') {
  403. // Directly-encoded character.
  404. if (posn >= charLength) {
  405. throw new ArgumentException (_("Arg_InsufficientSpace"), "chars");
  406. }
  407. chars[posn++] = (char)byteval;
  408. } else {
  409. // Start of a base64-encoded character.
  410. normal = false;
  411. prevIsPlus = true;
  412. }
  413. } else {
  414. // Process the next byte in a base64 sequence.
  415. if (byteval == (int)'-') {
  416. // End of a base64 sequence.
  417. if (prevIsPlus) {
  418. if (posn >= charLength) {
  419. throw new ArgumentException (_("Arg_InsufficientSpace"), "chars");
  420. }
  421. chars[posn++] = '+';
  422. }
  423. // RFC1642 Rule #2
  424. // When decoding, any bits at the end of the Modified Base64 sequence that
  425. // do not constitute a complete 16-bit Unicode character are discarded.
  426. // If such discarded bits are non-zero the sequence is ill-formed.
  427. if (leftOverBits != 0)
  428. throw new FormatException ("unused bits not zero");
  429. normal = true;
  430. } else if ((b64value = base64[byteval]) != -1) {
  431. // Extra character in a base64 sequence.
  432. leftOverBits = (leftOverBits << 6) | b64value;
  433. leftOverSize += 6;
  434. if (leftOverSize >= 16) {
  435. if (posn >= charLength) {
  436. throw new ArgumentException (_("Arg_InsufficientSpace"), "chars");
  437. }
  438. leftOverSize -= 16;
  439. chars[posn++] = (char)(leftOverBits >> leftOverSize);
  440. leftOverBits &= ((1 << leftOverSize) - 1);
  441. }
  442. } else {
  443. // Normal character terminating a base64 sequence.
  444. if (leftOverSize > 0) {
  445. if (posn >= charLength) {
  446. throw new ArgumentException (_("Arg_InsufficientSpace"), "chars");
  447. }
  448. chars[posn++] = (char)(leftOverBits << (16 - leftOverSize));
  449. leftOverSize = 0;
  450. leftOverBits = 0;
  451. }
  452. if (posn >= charLength) {
  453. throw new ArgumentException (_("Arg_InsufficientSpace"), "chars");
  454. }
  455. chars[posn++] = (char)byteval;
  456. normal = true;
  457. }
  458. prevIsPlus = false;
  459. }
  460. }
  461. leftOver = (leftOverBits | (leftOverSize << 16) |
  462. (normal ? 0 : 0x01000000) |
  463. (prevIsPlus ? 0x02000000 : 0));
  464. // Return the final length to the caller.
  465. return posn - charIndex;
  466. }
  467. // Get the characters that result from decoding a byte buffer.
  468. public override int GetChars (byte[] bytes, int byteIndex, int byteCount,
  469. char[] chars, int charIndex)
  470. {
  471. int leftOver = 0;
  472. return InternalGetChars (bytes, byteIndex, byteCount, chars, charIndex, ref leftOver);
  473. }
  474. // Get the maximum number of bytes needed to encode a
  475. // specified number of characters.
  476. public override int GetMaxByteCount (int charCount)
  477. {
  478. if (charCount < 0) {
  479. throw new ArgumentOutOfRangeException ("charCount", _("ArgRange_NonNegative"));
  480. }
  481. if (charCount == 0)
  482. return 0;
  483. return 8 * (int) (charCount / 3) + (charCount % 3) * 3 + 2;
  484. }
  485. // Get the maximum number of characters needed to decode a
  486. // specified number of bytes.
  487. public override int GetMaxCharCount (int byteCount)
  488. {
  489. if (byteCount < 0) {
  490. throw new ArgumentOutOfRangeException ("byteCount", _("ArgRange_NonNegative"));
  491. }
  492. return byteCount;
  493. }
  494. // Get a UTF7-specific decoder that is attached to this instance.
  495. public override Decoder GetDecoder ()
  496. {
  497. return new UTF7Decoder ();
  498. }
  499. // Get a UTF7-specific encoder that is attached to this instance.
  500. public override Encoder GetEncoder ()
  501. {
  502. return new UTF7Encoder (allowOptionals);
  503. }
  504. // UTF-7 decoder implementation.
  505. private sealed class UTF7Decoder : Decoder
  506. {
  507. // Internal state.
  508. private int leftOver;
  509. // Constructor.
  510. public UTF7Decoder ()
  511. {
  512. leftOver = 0;
  513. }
  514. // Override inherited methods.
  515. public override int GetCharCount (byte[] bytes, int index, int count)
  516. {
  517. return InternalGetCharCount (bytes, index, count, leftOver);
  518. }
  519. public override int GetChars (byte[] bytes, int byteIndex,
  520. int byteCount, char[] chars,
  521. int charIndex)
  522. {
  523. return InternalGetChars (bytes, byteIndex, byteCount, chars, charIndex, ref leftOver);
  524. }
  525. } // class UTF7Decoder
  526. // UTF-7 encoder implementation.
  527. private sealed class UTF7Encoder : Encoder
  528. {
  529. private bool allowOptionals;
  530. private int leftOver;
  531. // Constructor.
  532. public UTF7Encoder (bool allowOptionals)
  533. {
  534. this.allowOptionals = allowOptionals;
  535. this.leftOver = 0;
  536. }
  537. // Override inherited methods.
  538. public override int GetByteCount (char[] chars, int index,
  539. int count, bool flush)
  540. {
  541. return InternalGetByteCount
  542. (chars, index, count, flush, leftOver, allowOptionals);
  543. }
  544. public override int GetBytes (char[] chars, int charIndex,
  545. int charCount, byte[] bytes,
  546. int byteIndex, bool flush)
  547. {
  548. return InternalGetBytes (chars, charIndex, charCount,
  549. bytes, byteIndex, flush,
  550. ref leftOver, allowOptionals);
  551. }
  552. } // class UTF7Encoder
  553. }; // class UTF7Encoding
  554. }; // namespace System.Text