/core/externals/update-engine/externals/google-toolbox-for-mac/Foundation/GTMStringEncoding.h

http://macfuse.googlecode.com/ · C++ Header · 88 lines · 32 code · 12 blank · 44 comment · 0 complexity · 7fde3bdac8fdde6e2aec2603acf2e696 MD5 · raw file

  1. //
  2. // GTMStringEncoding.h
  3. //
  4. // Copyright 2010 Google Inc.
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7. // use this file except in compliance with the License. You may obtain a copy
  8. // of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. // License for the specific language governing permissions and limitations under
  16. // the License.
  17. //
  18. #import <Foundation/Foundation.h>
  19. #import "GTMDefines.h"
  20. // A generic class for arbitrary base-2 to 128 string encoding and decoding.
  21. @interface GTMStringEncoding : NSObject {
  22. @private
  23. NSData *charMapData_;
  24. char *charMap_;
  25. int reverseCharMap_[128];
  26. int shift_;
  27. int mask_;
  28. BOOL doPad_;
  29. char paddingChar_;
  30. int padLen_;
  31. }
  32. // Create a new, autoreleased GTMStringEncoding object with a standard encoding.
  33. + (id)binaryStringEncoding;
  34. + (id)hexStringEncoding;
  35. + (id)rfc4648Base32StringEncoding;
  36. + (id)rfc4648Base32HexStringEncoding;
  37. + (id)crockfordBase32StringEncoding;
  38. + (id)rfc4648Base64StringEncoding;
  39. + (id)rfc4648Base64WebsafeStringEncoding;
  40. // Create a new, autoreleased GTMStringEncoding object with the given string,
  41. // as described below.
  42. + (id)stringEncodingWithString:(NSString *)string;
  43. // Initialize a new GTMStringEncoding object with the string.
  44. //
  45. // The length of the string must be a power of 2, at least 2 and at most 128.
  46. // Only 7-bit ASCII characters are permitted in the string.
  47. //
  48. // These characters are the canonical set emitted during encoding.
  49. // If the characters have alternatives (e.g. case, easily transposed) then use
  50. // addDecodeSynonyms: to configure them.
  51. - (id)initWithString:(NSString *)string;
  52. // Add decoding synonyms as specified in the synonyms argument.
  53. //
  54. // It should be a sequence of one previously reverse mapped character,
  55. // followed by one or more non-reverse mapped character synonyms.
  56. // Only 7-bit ASCII characters are permitted in the string.
  57. //
  58. // e.g. If a GTMStringEncoder object has already been initialised with a set
  59. // of characters excluding I, L and O (to avoid confusion with digits) and you
  60. // want to accept them as digits you can call addDecodeSynonyms:@"0oO1iIlL".
  61. - (void)addDecodeSynonyms:(NSString *)synonyms;
  62. // A sequence of characters to ignore if they occur during encoding.
  63. // Only 7-bit ASCII characters are permitted in the string.
  64. - (void)ignoreCharacters:(NSString *)chars;
  65. // Indicates whether padding is performed during encoding.
  66. - (BOOL)doPad;
  67. - (void)setDoPad:(BOOL)doPad;
  68. // Sets the padding character to use during encoding.
  69. - (void)setPaddingChar:(char)c;
  70. // Encode a raw binary buffer to a 7-bit ASCII string.
  71. - (NSString *)encode:(NSData *)data;
  72. - (NSString *)encodeString:(NSString *)string;
  73. // Decode a 7-bit ASCII string to a raw binary buffer.
  74. - (NSData *)decode:(NSString *)string;
  75. - (NSString *)stringByDecoding:(NSString *)string;
  76. @end