PageRenderTime 76ms CodeModel.GetById 59ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/core/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
19#import <Foundation/Foundation.h>
20#import "GTMDefines.h"
21
22// A generic class for arbitrary base-2 to 128 string encoding and decoding.
23@interface GTMStringEncoding : NSObject {
24 @private
25  NSData *charMapData_;
26  char *charMap_;
27  int reverseCharMap_[128];
28  int shift_;
29  int mask_;
30  BOOL doPad_;
31  char paddingChar_;
32  int padLen_;
33}
34
35// Create a new, autoreleased GTMStringEncoding object with a standard encoding.
36+ (id)binaryStringEncoding;
37+ (id)hexStringEncoding;
38+ (id)rfc4648Base32StringEncoding;
39+ (id)rfc4648Base32HexStringEncoding;
40+ (id)crockfordBase32StringEncoding;
41+ (id)rfc4648Base64StringEncoding;
42+ (id)rfc4648Base64WebsafeStringEncoding;
43
44// Create a new, autoreleased GTMStringEncoding object with the given string,
45// as described below.
46+ (id)stringEncodingWithString:(NSString *)string;
47
48// Initialize a new GTMStringEncoding object with the string.
49//
50// The length of the string must be a power of 2, at least 2 and at most 128.
51// Only 7-bit ASCII characters are permitted in the string.
52//
53// These characters are the canonical set emitted during encoding.
54// If the characters have alternatives (e.g. case, easily transposed) then use
55// addDecodeSynonyms: to configure them.
56- (id)initWithString:(NSString *)string;
57
58// Add decoding synonyms as specified in the synonyms argument.
59//
60// It should be a sequence of one previously reverse mapped character,
61// followed by one or more non-reverse mapped character synonyms.
62// Only 7-bit ASCII characters are permitted in the string.
63//
64// e.g. If a GTMStringEncoder object has already been initialised with a set
65// of characters excluding I, L and O (to avoid confusion with digits) and you
66// want to accept them as digits you can call addDecodeSynonyms:@"0oO1iIlL".
67- (void)addDecodeSynonyms:(NSString *)synonyms;
68
69// A sequence of characters to ignore if they occur during encoding.
70// Only 7-bit ASCII characters are permitted in the string.
71- (void)ignoreCharacters:(NSString *)chars;
72
73// Indicates whether padding is performed during encoding.
74- (BOOL)doPad;
75- (void)setDoPad:(BOOL)doPad;
76
77// Sets the padding character to use during encoding.
78- (void)setPaddingChar:(char)c;
79
80// Encode a raw binary buffer to a 7-bit ASCII string.
81- (NSString *)encode:(NSData *)data;
82- (NSString *)encodeString:(NSString *)string;
83
84// Decode a 7-bit ASCII string to a raw binary buffer.
85- (NSData *)decode:(NSString *)string;
86- (NSString *)stringByDecoding:(NSString *)string;
87
88@end