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

NSString: + stringWithUtf8Buffer method

parent dce0b43c
......@@ -44,6 +44,7 @@
@interface NSString (StringUtils)
+ (id)stringWithWString:(const std::wstring&)string;
+ (id)stringWithAString:(const std::string&)string;
+ (id)stringWithUtf8Buffer:(const char*)string length:(size_t)len;
+ (NSMutableArray*)stringsArray:(const std::vector<std::wstring>&)sources;
- (std::wstring)stdwstring;
- (std::string)stdstring;
......
......@@ -30,6 +30,17 @@
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 {
size_t count = sources.size();
NSMutableArray* array = [NSMutableArray arrayWithCapacity:count];
......@@ -51,4 +62,4 @@
return std::string((char*)data.bytes, data.length);
}
@end
\ No newline at end of file
@end
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