From ebee536ebbe96bb3c4b6a563eabf15940b651a0c Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 30 Jul 2021 18:25:48 +0200 Subject: [PATCH] [src] Merge two implementations of converting a FourCC to a string. (#12305) --- src/CoreFoundation/CFBundle.cs | 11 +---------- src/Foundation/NSScriptCommandDescription.cs | 17 ++++------------- src/ObjCRuntime/Runtime.cs | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/CoreFoundation/CFBundle.cs b/src/CoreFoundation/CFBundle.cs index c3ebe5cf27..ebb38da48a 100644 --- a/src/CoreFoundation/CFBundle.cs +++ b/src/CoreFoundation/CFBundle.cs @@ -565,15 +565,6 @@ namespace CoreFoundation { [DllImport (Constants.CoreFoundationLibrary)] extern static void CFBundleGetPackageInfo (IntPtr bundle, out uint packageType, out uint packageCreator); - - static string FourCCToString (uint code) - { - return new string (new char [] { - (char) (byte) (code >> 24), - (char) (byte) (code >> 16), - (char) (byte) (code >> 8), - (char) (byte) code}); - } public PackageInfo Info { get { @@ -581,7 +572,7 @@ namespace CoreFoundation { uint creator = 0; CFBundleGetPackageInfo (handle, out type, out creator); - var creatorStr = FourCCToString (creator); + var creatorStr = Runtime.ToFourCCString (creator); switch (type) { case 1095782476: // ""APPL return new PackageInfo (CFBundle.PackageType.Application, creatorStr); diff --git a/src/Foundation/NSScriptCommandDescription.cs b/src/Foundation/NSScriptCommandDescription.cs index 68872ad5a2..fcf02bf995 100644 --- a/src/Foundation/NSScriptCommandDescription.cs +++ b/src/Foundation/NSScriptCommandDescription.cs @@ -26,15 +26,6 @@ namespace Foundation { NSScriptCommandDescriptionDictionary description = null; - static string ToFourCCString (int value) - { - return new string (new char [] { - (char) (byte) (value >> 24), - (char) (byte) (value >> 16), - (char) (byte) (value >> 8), - (char) (byte) value }); - } - static int ToIntValue (string fourCC) { if (fourCC.Length != 4) @@ -91,11 +82,11 @@ namespace Foundation { } public string AppleEventClassCode { - get { return ToFourCCString (FCCAppleEventClassCode); } + get { return Runtime.ToFourCCString (FCCAppleEventClassCode); } } public string AppleEventCode { - get { return ToFourCCString (FCCAppleEventCode); } + get { return Runtime.ToFourCCString (FCCAppleEventCode); } } public string GetTypeForArgument (string name) @@ -115,7 +106,7 @@ namespace Foundation { throw new ArgumentNullException (name); using (var nsName = new NSString (name)) { - return ToFourCCString (FCCAppleEventCodeForArgument (nsName)); + return Runtime.ToFourCCString (FCCAppleEventCodeForArgument (nsName)); } } @@ -127,7 +118,7 @@ namespace Foundation { } public string AppleEventCodeForReturnType { - get { return ToFourCCString (FCCAppleEventCodeForReturnType); } + get { return Runtime.ToFourCCString (FCCAppleEventCodeForReturnType); } } public NSScriptCommand CreateCommand () diff --git a/src/ObjCRuntime/Runtime.cs b/src/ObjCRuntime/Runtime.cs index cefe45c9d2..1de5a9f1a9 100644 --- a/src/ObjCRuntime/Runtime.cs +++ b/src/ObjCRuntime/Runtime.cs @@ -1712,6 +1712,20 @@ namespace ObjCRuntime { { NSLog (string.Format (format, args)); } + + internal static string ToFourCCString (uint value) + { + return ToFourCCString (unchecked((int) value)); + } + + internal static string ToFourCCString (int value) + { + return new string (new char [] { + (char) (byte) (value >> 24), + (char) (byte) (value >> 16), + (char) (byte) (value >> 8), + (char) (byte) value }); + } #endif // !COREBUILD static int MajorVersion = -1;