[vlc-commits] macosx: reorder string functions and add add some documentation

David Fuhrmann git at videolan.org
Thu Feb 27 17:47:43 CET 2014


vlc | branch: master | David Fuhrmann <david.fuhrmann at googlemail.com> | Thu Feb 27 17:44:44 2014 +0100| [2ec4f0a67afd8b790415a591cc9872647ead7be7] | committer: David Fuhrmann

macosx: reorder string functions and add add some documentation

No functional change.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2ec4f0a67afd8b790415a591cc9872647ead7be7
---

 modules/gui/macosx/StringUtility.h |    3 +-
 modules/gui/macosx/StringUtility.m |   93 +++++++++++++++++++++---------------
 2 files changed, 56 insertions(+), 40 deletions(-)

diff --git a/modules/gui/macosx/StringUtility.h b/modules/gui/macosx/StringUtility.h
index a412ff5..1e34d4a 100644
--- a/modules/gui/macosx/StringUtility.h
+++ b/modules/gui/macosx/StringUtility.h
@@ -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
diff --git a/modules/gui/macosx/StringUtility.m b/modules/gui/macosx/StringUtility.m
index 1498875..dc9f2cd 100644
--- a/modules/gui/macosx/StringUtility.m
+++ b/modules/gui/macosx/StringUtility.m
@@ -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]);



More information about the vlc-commits mailing list