xamarin-macios/tools/common/StringUtils.cs

107 строки
2.2 KiB
C#
Исходник Обычный вид История

using System;
using System.Text;
namespace Xamarin.Utils {
[generator] Register models with unique names to not match platform types. Fixes #3875. (#3879) * Move Registrar.SanitizeName to StringUtils.SanitizeObjectiveCName. * [generator] Register models with unique names to not match platform types. Fixes #3875. * [NSObject] Don't compare against a non-existent protocol. * [generator] Make it possible to register models like before if the binding developer wishes it. * [src] Make sure to not declare ObjC classes Apple already defines. Fixes these warnings at startup: Class DOMNodeFilter is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebKitLegacy.framework/Versions/A/WebKitLegacy (0x7fffa944a788) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8a9958). One of the two will be used. Which one is undefined. Class WebOpenPanelResultListener is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebKitLegacy.framework/Versions/A/WebKitLegacy (0x7fffa944e4c8) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8a9a98). One of the two will be used. Which one is undefined. Class WebPolicyDecisionListener is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebKitLegacy.framework/Versions/A/WebKitLegacy (0x7fffa944e838) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8a9ae8). One of the two will be used. Which one is undefined. Class MTLCaptureScope is implemented in both /System/Library/Frameworks/Metal.framework/Versions/A/Metal (0x7fffa806f1d0) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8aa858). One of the two will be used. Which one is undefined. Class JSExport is implemented in both /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/JavaScriptCore (0x7fffa7eb4f60) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8aaa38). One of the two will be used. Which one is undefined.
2018-04-06 18:24:07 +03:00
internal class StringUtils {
static StringUtils ()
{
PlatformID pid = Environment.OSVersion.Platform;
if (((int)pid != 128 && pid != PlatformID.Unix && pid != PlatformID.MacOSX))
shellQuoteChar = '"'; // Windows
else
shellQuoteChar = '\''; // !Windows
}
static char shellQuoteChar;
static char[] mustQuoteCharacters = new char [] { ' ', '\'', ',', '$', '\\' };
public static string Quote (string f)
{
if (String.IsNullOrEmpty (f))
return f ?? String.Empty;
if (f.IndexOfAny (mustQuoteCharacters) == -1)
return f;
var s = new StringBuilder ();
s.Append (shellQuoteChar);
foreach (var c in f) {
if (c == '\'' || c == '"' || c == '\\')
s.Append ('\\');
s.Append (c);
}
s.Append (shellQuoteChar);
return s.ToString ();
}
public static string Unquote (string input)
{
if (input == null || input.Length == 0 || input [0] != shellQuoteChar)
return input;
var builder = new StringBuilder ();
for (int i = 1; i < input.Length - 1; i++) {
char c = input [i];
if (c == '\\') {
builder.Append (input [i + 1]);
i++;
continue;
}
builder.Append (input [i]);
}
return builder.ToString ();
}
// Version.Parse requires, minimally, both major and minor parts.
// However we want to accept `11` as `11.0`
public static Version ParseVersion (string v)
{
int major;
if (int.TryParse (v, out major))
return new Version (major, 0);
return Version.Parse (v);
}
[generator] Register models with unique names to not match platform types. Fixes #3875. (#3879) * Move Registrar.SanitizeName to StringUtils.SanitizeObjectiveCName. * [generator] Register models with unique names to not match platform types. Fixes #3875. * [NSObject] Don't compare against a non-existent protocol. * [generator] Make it possible to register models like before if the binding developer wishes it. * [src] Make sure to not declare ObjC classes Apple already defines. Fixes these warnings at startup: Class DOMNodeFilter is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebKitLegacy.framework/Versions/A/WebKitLegacy (0x7fffa944a788) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8a9958). One of the two will be used. Which one is undefined. Class WebOpenPanelResultListener is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebKitLegacy.framework/Versions/A/WebKitLegacy (0x7fffa944e4c8) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8a9a98). One of the two will be used. Which one is undefined. Class WebPolicyDecisionListener is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebKitLegacy.framework/Versions/A/WebKitLegacy (0x7fffa944e838) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8a9ae8). One of the two will be used. Which one is undefined. Class MTLCaptureScope is implemented in both /System/Library/Frameworks/Metal.framework/Versions/A/Metal (0x7fffa806f1d0) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8aa858). One of the two will be used. Which one is undefined. Class JSExport is implemented in both /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/JavaScriptCore (0x7fffa7eb4f60) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8aaa38). One of the two will be used. Which one is undefined.
2018-04-06 18:24:07 +03:00
public static string SanitizeObjectiveCName (string name)
{
StringBuilder sb = null;
for (int i = 0; i < name.Length; i++) {
var ch = name [i];
switch (ch) {
case '.':
case '+':
case '/':
case '`':
case '@':
case '<':
case '>':
case '$':
case '-':
if (sb == null)
sb = new StringBuilder (name, 0, i, name.Length);
sb.Append ('_');
break;
default:
if (sb != null)
sb.Append (ch);
break;
}
}
if (sb != null)
return sb.ToString ();
return name;
}
}
static class StringExtensions
{
[generator] Register models with unique names to not match platform types. Fixes #3875. (#3879) * Move Registrar.SanitizeName to StringUtils.SanitizeObjectiveCName. * [generator] Register models with unique names to not match platform types. Fixes #3875. * [NSObject] Don't compare against a non-existent protocol. * [generator] Make it possible to register models like before if the binding developer wishes it. * [src] Make sure to not declare ObjC classes Apple already defines. Fixes these warnings at startup: Class DOMNodeFilter is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebKitLegacy.framework/Versions/A/WebKitLegacy (0x7fffa944a788) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8a9958). One of the two will be used. Which one is undefined. Class WebOpenPanelResultListener is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebKitLegacy.framework/Versions/A/WebKitLegacy (0x7fffa944e4c8) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8a9a98). One of the two will be used. Which one is undefined. Class WebPolicyDecisionListener is implemented in both /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebKitLegacy.framework/Versions/A/WebKitLegacy (0x7fffa944e838) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8a9ae8). One of the two will be used. Which one is undefined. Class MTLCaptureScope is implemented in both /System/Library/Frameworks/Metal.framework/Versions/A/Metal (0x7fffa806f1d0) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8aa858). One of the two will be used. Which one is undefined. Class JSExport is implemented in both /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/JavaScriptCore (0x7fffa7eb4f60) and /Users/builder/data/lanes/6035/0ca02336/source/xamarin-macios/tests/xharness/tmp-test-dir/dont link-mac-unified/bin/x86/Debug-unified/dont link.app/Contents/MacOS/dont link (0x10d8aaa38). One of the two will be used. Which one is undefined.
2018-04-06 18:24:07 +03:00
internal static string [] SplitLines (this string s) => s.Split (new [] { Environment.NewLine }, StringSplitOptions.None);
}
}