Plugin utilities: Moved encoding guesser to header
Moved the string encoding guesser/converter to the Plugin.h header, so it may be accessible from any plugin. I may make it a global member of something eventually, but a static inline for such a simple function should be fine for now. This function facilitates converting arbitrary 8 bit encoded strings to Unicode NSString objects. It should be used anywhere that UTF-8 is expected, but not necessarily guaranteed, and where other 8-bit encodings may also be supplied by a user's files. Not using this setup for string inputs has already led to failed UTF-8 decoding resulting in nil NSStrings being passed to the inline array or dictionary initializers, which results in crashes due to uncaught exceptions. Signed-off-by: Christopher Snowhill <kode54@gmail.com>swiftingly
parent
4b2cf22800
commit
f7dc6beda1
Audio
Plugins/HTTPSource
|
@ -98,3 +98,10 @@
|
||||||
|
|
||||||
- (int)putMetadataInURL:(NSURL *)url;
|
- (int)putMetadataInURL:(NSURL *)url;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
static NSString *guess_encoding_of_string(const char *input) {
|
||||||
|
NSString *ret = @"";
|
||||||
|
NSData *stringData = [NSData dataWithBytes:input length:strlen(input)];
|
||||||
|
[NSString stringEncodingForData:stringData encodingOptions:nil convertedString:&ret usedLossyConversion:nil];
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
|
@ -59,13 +59,6 @@ static size_t http_curl_write_wrapper(HTTPSource *fp, void *ptr, size_t size) {
|
||||||
return size - avail;
|
return size - avail;
|
||||||
}
|
}
|
||||||
|
|
||||||
static NSString *guess_encoding_of_string(const char *input) {
|
|
||||||
NSString *ret = @"";
|
|
||||||
NSData *stringData = [NSData dataWithBytes:input length:strlen(input)];
|
|
||||||
[NSString stringEncodingForData:stringData encodingOptions:nil convertedString:&ret usedLossyConversion:nil];
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int http_parse_shoutcast_meta(HTTPSource *fp, const char *meta, size_t size) {
|
static int http_parse_shoutcast_meta(HTTPSource *fp, const char *meta, size_t size) {
|
||||||
// DLog (@"reading %d bytes of metadata\n", size);
|
// DLog (@"reading %d bytes of metadata\n", size);
|
||||||
DLog(@"%s", meta);
|
DLog(@"%s", meta);
|
||||||
|
|
Loading…
Reference in New Issue