Commit 2ec4f0a6 authored by David Fuhrmann's avatar David Fuhrmann

macosx: reorder string functions and add add some documentation

No functional change.
parent 8afd622d
......@@ -47,14 +47,13 @@ unsigned int CocoaKeyToVLC(unichar i_key);
- (NSString *)localizedString:(const char *)psz;
- (NSString *)wrapString: (NSString *)o_in_string toWidth: (int)i_width;
- (NSString *)OSXStringKeyToString:(NSString *)theString;
- (NSString *)getCurrentTimeAsString:(input_thread_t *)p_input negative:(BOOL)b_negative;
- (NSString *)OSXStringKeyToString:(NSString *)theString;
- (NSString *)VLCKeyToString:(NSString *)theString;
- (unsigned int)VLCModifiersToCocoa:(NSString *)theString;
- (NSString *)b64Decode:(NSString *)string;
- (NSString *)b64EncodeAndFree:(char *)psz_string;
@end
......@@ -115,44 +115,6 @@ static VLCStringUtility *_o_sharedInstance = nil;
return o_out_string;
}
- (NSString *)OSXStringKeyToString:(NSString *)theString
{
if (![theString isEqualToString:@""]) {
/* remove cruft */
if ([theString characterAtIndex:([theString length] - 1)] != 0x2b)
theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
else {
theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
theString = [NSString stringWithFormat:@"%@+", theString];
}
if ([theString characterAtIndex:([theString length] - 1)] != 0x2d)
theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
else {
theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
theString = [NSString stringWithFormat:@"%@-", theString];
}
/* modifiers */
theString = [theString stringByReplacingOccurrencesOfString:@"Command" withString: [NSString stringWithUTF8String:"\xE2\x8C\x98"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Alt" withString: [NSString stringWithUTF8String:"\xE2\x8C\xA5"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Shift" withString: [NSString stringWithUTF8String:"\xE2\x87\xA7"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Ctrl" withString: [NSString stringWithUTF8String:"\xE2\x8C\x83"]];
/* show non-character keys correctly */
theString = [theString stringByReplacingOccurrencesOfString:@"Right" withString:[NSString stringWithUTF8String:"\xE2\x86\x92"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Left" withString:[NSString stringWithUTF8String:"\xE2\x86\x90"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Page Up" withString:[NSString stringWithUTF8String:"\xE2\x87\x9E"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Page Down" withString:[NSString stringWithUTF8String:"\xE2\x87\x9F"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Up" withString:[NSString stringWithUTF8String:"\xE2\x86\x91"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Down" withString:[NSString stringWithUTF8String:"\xE2\x86\x93"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Enter" withString:[NSString stringWithUTF8String:"\xe2\x86\xb5"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Tab" withString:[NSString stringWithUTF8String:"\xe2\x87\xa5"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Delete" withString:[NSString stringWithUTF8String:"\xe2\x8c\xab"]]; /* capitalize plain characters to suit the menubar's look */
theString = [theString capitalizedString];
}
else
theString = [NSString stringWithString:_NS("Not Set")];
return theString;
}
- (NSString *)getCurrentTimeAsString:(input_thread_t *)p_input negative:(BOOL)b_negative
{
assert(p_input != nil);
......@@ -211,6 +173,9 @@ static struct
{0,0}
};
/*
* Takes the first value of an cocoa key string, and converts it to VLCs int representation.
*/
unsigned int CocoaKeyToVLC(unichar i_key)
{
unsigned int i;
......@@ -223,6 +188,52 @@ unsigned int CocoaKeyToVLC(unichar i_key)
return (unsigned int)i_key;
}
/*
* Converts VLC key string to a prettified version, for hotkey settings.
* The returned string adapts similar how its done within the cocoa framework when setting this
* key to menu items.
*/
- (NSString *)OSXStringKeyToString:(NSString *)theString
{
if (![theString isEqualToString:@""]) {
/* remove cruft */
if ([theString characterAtIndex:([theString length] - 1)] != 0x2b)
theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
else {
theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
theString = [NSString stringWithFormat:@"%@+", theString];
}
if ([theString characterAtIndex:([theString length] - 1)] != 0x2d)
theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
else {
theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
theString = [NSString stringWithFormat:@"%@-", theString];
}
/* modifiers */
theString = [theString stringByReplacingOccurrencesOfString:@"Command" withString: [NSString stringWithUTF8String:"\xE2\x8C\x98"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Alt" withString: [NSString stringWithUTF8String:"\xE2\x8C\xA5"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Shift" withString: [NSString stringWithUTF8String:"\xE2\x87\xA7"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Ctrl" withString: [NSString stringWithUTF8String:"\xE2\x8C\x83"]];
/* show non-character keys correctly */
theString = [theString stringByReplacingOccurrencesOfString:@"Right" withString:[NSString stringWithUTF8String:"\xE2\x86\x92"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Left" withString:[NSString stringWithUTF8String:"\xE2\x86\x90"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Page Up" withString:[NSString stringWithUTF8String:"\xE2\x87\x9E"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Page Down" withString:[NSString stringWithUTF8String:"\xE2\x87\x9F"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Up" withString:[NSString stringWithUTF8String:"\xE2\x86\x91"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Down" withString:[NSString stringWithUTF8String:"\xE2\x86\x93"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Enter" withString:[NSString stringWithUTF8String:"\xe2\x86\xb5"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Tab" withString:[NSString stringWithUTF8String:"\xe2\x87\xa5"]];
theString = [theString stringByReplacingOccurrencesOfString:@"Delete" withString:[NSString stringWithUTF8String:"\xe2\x8c\xab"]]; /* capitalize plain characters to suit the menubar's look */
theString = [theString capitalizedString];
}
else
theString = [NSString stringWithString:_NS("Not Set")];
return theString;
}
/*
* Converts VLC key string to cocoa modifiers which can be used as setKeyEquivalent for menu items
*/
- (unsigned int)VLCModifiersToCocoa:(NSString *)theString
{
unsigned int new = 0;
......@@ -238,6 +249,9 @@ unsigned int CocoaKeyToVLC(unichar i_key)
return new;
}
/*
* Converts VLC key to cocoa string which can be used as setKeyEquivalentModifierMask for menu items
*/
- (NSString *)VLCKeyToString:(NSString *)theString
{
if (![theString isEqualToString:@""]) {
......@@ -326,6 +340,9 @@ unsigned int CocoaKeyToVLC(unichar i_key)
return theString;
}
#pragma mark -
#pragma mark base64 helpers
- (NSString *)b64Decode:(NSString *)string
{
char *psz_decoded_string = vlc_b64_decode([string UTF8String]);
......
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