Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOEncodingConverter Class Reference

#include <OOEncodingConverter.h>

+ Inheritance diagram for OOEncodingConverter:
+ Collaboration diagram for OOEncodingConverter:

Instance Methods

(id) - initWithEncoding:substitutions:
 
(id) - initWithFontPList:
 
(NSData *) - convertString:
 
(NSStringEncoding) - encoding
 
(void) - dealloc [implementation]
 
(NSString *) - descriptionComponents [implementation]
 
(NSData *) - performConversionForString: [implementation]
 

Private Attributes

NSStringEncoding _encoding
 
OOCache_cache
 
NSDictionary * _substitutions
 

Detailed Description

Definition at line 39 of file OOEncodingConverter.h.

Method Documentation

◆ convertString:

- (NSData *) convertString: (NSString *) string

Definition at line 249 of file OOEncodingConverter.m.

125 :(NSString *)string
126{
127 NSData *data = nil;
128
129#if USE_COMPATIBILITY_MAPPING
130 // Convert to Unicode Normalization Form KC (that is, minimize the use of combining modifiers while avoiding precomposed ligatures)
131 string = [string precomposedStringWithCompatibilityMapping];
132#endif
133
134 if (string == nil) return [NSData data];
135
136 data = [_cache objectForKey:string];
137 if (data == nil)
138 {
139 data = [self performConversionForString:string];
140 if (data != nil) [_cache setObject:data forKey:string];
141
142#if PROFILE_ENCODING_CONVERTER
143 ++sCacheMisses;
144 }
145 else
146 {
147 ++sCacheHits;
148#endif
149 }
150
151 return data;
152}
return nil

References kWindowsCyrillicStr, kWindowsGreekStr, kWindowsLatin1Str, kWindowsLatin2Str, and kWindowsTurkishStr.

Referenced by HeadUpDisplay::OODrawStringQuadsAligned, and HeadUpDisplay::OORectFromString.

+ Here is the caller graph for this function:

◆ dealloc

- (void) dealloc
implementation

Definition at line 249 of file OOEncodingConverter.m.

103{
104 [_cache release];
105 [_substitutions release];
106
107#if PROFILE_ENCODING_CONVERTER
108 sProfiledConverter = nil;
109 [sProfileTimer invalidate];
110 sProfileTimer = nil;
111 sCacheHits = 0;
112 sCacheMisses = 0;
113#endif
114
115 [super dealloc];
116}

◆ descriptionComponents

- (NSString *) descriptionComponents
implementation

Definition at line 249 of file OOEncodingConverter.m.

120{
121 return [NSString stringWithFormat:@"encoding: %lu", _encoding];
122}

◆ encoding

- (NSStringEncoding) encoding

Definition at line 249 of file OOEncodingConverter.m.

156{
157 return _encoding;
158}
NSStringEncoding _encoding

◆ initWithEncoding:substitutions:

- (id) initWithEncoding: (NSStringEncoding) encoding
substitutions: (NSDictionary *) substitutions 

Definition at line 249 of file OOEncodingConverter.m.

72 :(NSStringEncoding)encoding substitutions:(NSDictionary *)substitutions
73{
74 self = [super init];
75 if (self != nil)
76 {
77 _cache = [[OOCache alloc] init];
78 [_cache setPruneThreshold:kCachePruneThreshold];
79 [_cache setName:@"Text encoding"];
80 _substitutions = [substitutions copy];
82
83#if PROFILE_ENCODING_CONVERTER
84 if (sProfiledConverter == nil)
85 {
86 sProfiledConverter = self;
87 sProfileTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(profileFire:) userInfo:nil repeats:YES];
88 }
89#endif
90 }
91
92 return self;
93}
NSDictionary * _substitutions
NSStringEncoding encoding()

◆ initWithFontPList:

- (id) initWithFontPList: (NSDictionary *) fontPList

Definition at line 249 of file OOEncodingConverter.m.

96 :(NSDictionary *)fontPList
97{
98 return [self initWithEncoding:EncodingFromString([fontPList oo_stringForKey:@"encoding"]) substitutions:[fontPList oo_dictionaryForKey:@"substitutions"]];
99}

◆ performConversionForString:

- (NSData *) performConversionForString: (NSString *) string
implementation

Provided by category OOEncodingConverter(Private).

Definition at line 249 of file OOEncodingConverter.m.

165 :(NSString *)string
166{
167 NSString *subst = nil;
168 NSEnumerator *substEnum = nil;
169 NSMutableString *mutable = nil;
170
171 mutable = [[string mutableCopy] autorelease];
172 if (mutable == nil) return nil;
173
174 for (substEnum = [_substitutions keyEnumerator]; (subst = [substEnum nextObject]); )
175 {
176 [mutable replaceOccurrencesOfString:subst
177 withString:[_substitutions objectForKey:subst]
178 options:0
179 range:NSMakeRange(0, [mutable length])];
180 }
181
182 return [mutable dataUsingEncoding:_encoding allowLossyConversion:YES];
183}

Member Data Documentation

◆ _cache

- (OOCache*) _cache
private

Definition at line 43 of file OOEncodingConverter.h.

◆ _encoding

- (NSStringEncoding) _encoding
private

Definition at line 42 of file OOEncodingConverter.h.

◆ _substitutions

- (NSDictionary*) _substitutions
private

Definition at line 44 of file OOEncodingConverter.h.


The documentation for this class was generated from the following files: