Commit 95d9d8bc authored by Oleg Korshul's avatar Oleg Korshul

NSString: + stringWithUtf8Buffer method

parent dce0b43c
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
@interface NSString (StringUtils) @interface NSString (StringUtils)
+ (id)stringWithWString:(const std::wstring&)string; + (id)stringWithWString:(const std::wstring&)string;
+ (id)stringWithAString:(const std::string&)string; + (id)stringWithAString:(const std::string&)string;
+ (id)stringWithUtf8Buffer:(const char*)string length:(size_t)len;
+ (NSMutableArray*)stringsArray:(const std::vector<std::wstring>&)sources; + (NSMutableArray*)stringsArray:(const std::vector<std::wstring>&)sources;
- (std::wstring)stdwstring; - (std::wstring)stdwstring;
- (std::string)stdstring; - (std::string)stdstring;
......
...@@ -30,6 +30,17 @@ ...@@ -30,6 +30,17 @@
encoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingUTF8)]; encoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingUTF8)];
} }
+ (id)stringWithUtf8Buffer:(const char*)string length:(size_t)len
{
if (len < 1) {
return @"";
}
return [[NSString alloc] initWithBytes:string
length:len*sizeof(char)
encoding:CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingUTF8)];
}
+ (NSMutableArray*)stringsArray:(const std::vector<std::wstring>&)sources { + (NSMutableArray*)stringsArray:(const std::vector<std::wstring>&)sources {
size_t count = sources.size(); size_t count = sources.size();
NSMutableArray* array = [NSMutableArray arrayWithCapacity:count]; NSMutableArray* array = [NSMutableArray arrayWithCapacity:count];
...@@ -51,4 +62,4 @@ ...@@ -51,4 +62,4 @@
return std::string((char*)data.bytes, data.length); return std::string((char*)data.bytes, data.length);
} }
@end @end
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment