summaryrefslogtreecommitdiff
path: root/Assets/ThirdParty/VRM/VRM/UniGLTF/Scripts/Extensions/StringExtensions.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/ThirdParty/VRM/VRM/UniGLTF/Scripts/Extensions/StringExtensions.cs')
-rw-r--r--Assets/ThirdParty/VRM/VRM/UniGLTF/Scripts/Extensions/StringExtensions.cs76
1 files changed, 76 insertions, 0 deletions
diff --git a/Assets/ThirdParty/VRM/VRM/UniGLTF/Scripts/Extensions/StringExtensions.cs b/Assets/ThirdParty/VRM/VRM/UniGLTF/Scripts/Extensions/StringExtensions.cs
new file mode 100644
index 00000000..92dbdbb7
--- /dev/null
+++ b/Assets/ThirdParty/VRM/VRM/UniGLTF/Scripts/Extensions/StringExtensions.cs
@@ -0,0 +1,76 @@
+using System.IO;
+using System.Text.RegularExpressions;
+using UnityEngine;
+
+namespace UniGLTF
+{
+ public static class StringExtensions
+ {
+ public static string ToLowerCamelCase(this string lower)
+ {
+ return lower.Substring(0, 1).ToLower() + lower.Substring(1);
+ }
+ public static string ToUpperCamelCase(this string lower)
+ {
+ return lower.Substring(0, 1).ToUpper() + lower.Substring(1);
+ }
+
+ static string m_unityBasePath;
+ public static string UnityBasePath
+ {
+ get
+ {
+ if (m_unityBasePath == null)
+ {
+ m_unityBasePath = Path.GetFullPath(Application.dataPath + "/..").Replace("\\", "/");
+ }
+ return m_unityBasePath;
+ }
+ }
+
+ public static string AssetPathToFullPath(this string path)
+ {
+ return UnityBasePath + "/" + path;
+ }
+
+ public static bool StartsWithUnityAssetPath(this string path)
+ {
+ return path.Replace("\\", "/").StartsWith(UnityBasePath + "/Assets");
+ }
+
+ public static string ToUnityRelativePath(this string path)
+ {
+ path = path.Replace("\\", "/");
+ if (path.StartsWith(UnityBasePath))
+ {
+ return path.Substring(UnityBasePath.Length + 1);
+ }
+
+ //Debug.LogWarningFormat("{0} is starts with {1}", path, basePath);
+ return path;
+ }
+
+ static readonly char[] EscapeChars = new char[]
+ {
+ '\\',
+ '/',
+ ':',
+ '*',
+ '?',
+ '"',
+ '<',
+ '>',
+ '|',
+ };
+ public static string EscapeFilePath(this string path)
+ {
+ path = Regex.Replace(path, @"[\u0000-\u001F\u007F]", "+");
+
+ foreach(var x in EscapeChars)
+ {
+ path = path.Replace(x, '+');
+ }
+ return path;
+ }
+ }
+}