Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Use the invariant culture for capitalization when generating code #2156

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Assets/Editor/AddScenesToBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using System;

[InitializeOnLoad]
public class AddScenesToBuild : EditorWindow
Expand Down Expand Up @@ -66,7 +67,7 @@ private static bool IsPathInExcludedFolder(string path)
// Check if the path or any part of it contains any of the excluded folder names
foreach (string folder in excludedFolders)
{
if (path.ToLower().Contains(folder.ToLower()))
if (path.Contains(folder, StringComparison.InvariantCultureIgnoreCase))
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ protected string FirstLetterToUpper(string str)
if (String.IsNullOrEmpty(str))
return null;
else if (str.Length == 1)
return str.ToUpper();
return str.ToUpperInvariant();
else
return char.ToUpper(str[0]) + str.Substring(1);
return char.ToUpperInvariant(str[0]) + str.Substring(1);
}

protected void ShowMessage(string msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ private string FirstLetterToUpper(string str)
if (String.IsNullOrEmpty(str))
return null;
else if (str.Length == 1)
return str.ToUpper();
return str.ToUpperInvariant();
else
return char.ToUpper(str[0]) + str.Substring(1);
return char.ToUpperInvariant(str[0]) + str.Substring(1);
}

private void ShowMessage(string msg)
Expand Down
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ however, it has to be formatted properly to pass verification tests.
- Fixed the on hover behaviour of the two plus buttons in the Input Actions Editor window [ISXB-1327](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1327)
- Fixed an issue on macOS which didn't detect up-left DPAD presses for Xbox controllers. [ISXB-810](https://issuetracker.unity3d.com/issues/macos-d-pad-upper-left-corner-is-not-logged-with-the-xbox-controller)
- Fixed Input Actions code generation overwriting user files when the names happened to match. [ISXB-1257](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1257)
- Fixed Input Actions code generation using locale-dependent rules when lowercasing and uppercasing strings. [ISXB-1406](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1406)
- Fixed an issue when providing JoinPlayer with a specific split screen index. [ISXB-897](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-897)

## [1.14.0] - 2025-03-20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,7 @@ public InputControlLayout ToLayout()
// Before render behavior.
if (!string.IsNullOrEmpty(beforeRender))
{
var beforeRenderLowerCase = beforeRender.ToLower();
var beforeRenderLowerCase = beforeRender.ToLowerInvariant();
if (beforeRenderLowerCase == "ignore")
layout.m_UpdateBeforeRender = false;
else if (beforeRenderLowerCase == "update")
Expand All @@ -1685,7 +1685,7 @@ public InputControlLayout ToLayout()
// CanRunInBackground flag.
if (!string.IsNullOrEmpty(runInBackground))
{
var runInBackgroundLowerCase = runInBackground.ToLower();
var runInBackgroundLowerCase = runInBackground.ToLowerInvariant();
if (runInBackgroundLowerCase == "enabled")
layout.canRunInBackground = true;
else if (runInBackgroundLowerCase == "disabled")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,15 +559,15 @@ private static bool StringMatches(Substring str, InternedString matchTo)
return true; // Wildcard at end of string so rest is matched.

++posInStr;
nextChar = char.ToLower(str[posInStr], CultureInfo.InvariantCulture);
nextChar = char.ToLowerInvariant(str[posInStr]);

while (posInMatchTo < matchToLength && matchToLowerCase[posInMatchTo] != nextChar)
++posInMatchTo;

if (posInMatchTo == matchToLength)
return false; // Matched all the way to end of matchTo but there's more in str after the wildcard.
}
else if (char.ToLower(nextChar, CultureInfo.InvariantCulture) != matchToLowerCase[posInMatchTo])
else if (char.ToLowerInvariant(nextChar) != matchToLowerCase[posInMatchTo])
{
return false;
}
Expand Down Expand Up @@ -1156,7 +1156,7 @@ private static bool MatchPathComponent(string component, string path, ref int in
}

var charInComponent = component[indexInComponent];
if (charInComponent == nextCharInPath || char.ToLower(charInComponent, CultureInfo.InvariantCulture) == char.ToLower(nextCharInPath, CultureInfo.InvariantCulture))
if (charInComponent == nextCharInPath || char.ToLowerInvariant(charInComponent) == char.ToLowerInvariant(nextCharInPath))
{
++indexInComponent;
++indexInPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,18 @@ protected override void RefreshConfiguration()
return;
}

var textInfo = CultureInfo.InvariantCulture.TextInfo;
// We need to lower case first because ToTitleCase preserves upper casing.
// For example on Swedish Windows layout right shift display name is "HÖGER SKIFT".
// Just passing it to ToTitleCase won't change anything. But passing "höger skift" will return "Höger Skift".
var keyNameLowerCase = textInfo.ToLower(rawKeyName);
var keyNameLowerCase = rawKeyName.ToLowerInvariant();

if (string.IsNullOrEmpty(keyNameLowerCase))
{
displayName = rawKeyName;
return;
}

var textInfo = CultureInfo.InvariantCulture.TextInfo;
displayName = textInfo.ToTitleCase(keyNameLowerCase);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ private static void GenerateWrapperCode(AssetImportContext ctx, InputActionAsset
var directory = Path.GetDirectoryName(assetPath);
wrapperFilePath = Path.Combine(directory, wrapperFilePath);
}
else if (!wrapperFilePath.ToLower().StartsWith("assets/") &&
!wrapperFilePath.ToLower().StartsWith("assets\\"))
else if (!wrapperFilePath.StartsWith("assets/", StringComparison.InvariantCultureIgnoreCase) &&
!wrapperFilePath.StartsWith("assets\\", StringComparison.InvariantCultureIgnoreCase))
{
// User-specified file in Assets/ folder.
wrapperFilePath = Path.Combine("Assets", wrapperFilePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void Initialize(string label, string tooltip, string defaultName, Func<fl
m_GetDefaultValue = getDefaultValue;
m_ToggleLabel = EditorGUIUtility.TrTextContent("Default",
defaultComesFromInputSettings
? $"If enabled, the default {label.ToLower()} configured globally in the input settings is used. See Edit >> Project Settings... >> Input (NEW)."
? $"If enabled, the default {label.ToLowerInvariant()} configured globally in the input settings is used. See Edit >> Project Settings... >> Input (NEW)."
: "If enabled, the default value is used.");
m_ValueLabel = EditorGUIUtility.TrTextContent(label, tooltip);
if (defaultComesFromInputSettings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ public static void RegisterPlatform(BuildTarget target)
private static bool IsPluginInstalled()
{
var registeredPackages = UnityEditor.PackageManager.PackageInfo.GetAllRegisteredPackages();
var plugInName = PlugInName + EditorUserBuildSettings.activeBuildTarget.ToString().ToLower();
var plugInName = PlugInName + EditorUserBuildSettings.activeBuildTarget.ToString();
foreach (var package in registeredPackages)
{
if (package.name.Equals(plugInName))
if (package.name.Equals(plugInName, StringComparison.InvariantCultureIgnoreCase))
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ protected virtual AdvancedDropdownItem Search(string searchString)
if (searchTree == null)
{
// Support multiple search words separated by spaces.
var searchWords = searchString.ToLower().Split(' ');
var searchWords = searchString.ToLowerInvariant().Split(' ');

// We keep two lists. Matches that matches the start of an item always get first priority.
var matchesStart = new List<AdvancedDropdownItem>();
var matchesWithin = new List<AdvancedDropdownItem>();

foreach (var e in m_SearchableElements)
{
var name = e.searchableName.ToLower().Replace(" ", "");
var name = e.searchableName.ToLowerInvariant().Replace(" ", "");
AddMatchItem(e, name, searchWords, matchesStart, matchesWithin);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private InputControlLayout Build()
if (inheritedLayout != null)
featureName = ConvertPotentialAliasToName(inheritedLayout, featureName);

featureName = featureName.ToLower();
featureName = featureName.ToLowerInvariant();

if (IsSubControl(featureName))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static string MakeTypeName(string name, string suffix = "")
{
var symbolName = MakeIdentifier(name, suffix);
if (char.IsLower(symbolName[0]))
symbolName = char.ToUpper(symbolName[0]) + symbolName.Substring(1);
symbolName = char.ToUpperInvariant(symbolName[0]) + symbolName.Substring(1);
return symbolName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,26 +171,22 @@ public override string ToString()

public static bool operator==(InternedString a, string b)
{
return string.Compare(a.m_StringLowerCase, b.ToLower(CultureInfo.InvariantCulture),
StringComparison.InvariantCultureIgnoreCase) == 0;
return string.Compare(a.m_StringLowerCase, b, StringComparison.InvariantCultureIgnoreCase) == 0;
}

public static bool operator!=(InternedString a, string b)
{
return string.Compare(a.m_StringLowerCase, b.ToLower(CultureInfo.InvariantCulture),
StringComparison.InvariantCultureIgnoreCase) != 0;
return string.Compare(a.m_StringLowerCase, b, StringComparison.InvariantCultureIgnoreCase) != 0;
}

public static bool operator==(string a, InternedString b)
{
return string.Compare(a.ToLower(CultureInfo.InvariantCulture), b.m_StringLowerCase,
StringComparison.InvariantCultureIgnoreCase) == 0;
return string.Compare(a, b.m_StringLowerCase, StringComparison.InvariantCultureIgnoreCase) == 0;
}

public static bool operator!=(string a, InternedString b)
{
return string.Compare(a.ToLower(CultureInfo.InvariantCulture), b.m_StringLowerCase,
StringComparison.InvariantCultureIgnoreCase) != 0;
return string.Compare(a, b.m_StringLowerCase, StringComparison.InvariantCultureIgnoreCase) != 0;
}

public static bool operator<(InternedString left, InternedString right)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ public static string MakeUniqueName<TExisting>(string baseName, IEnumerable<TExi
return baseName;

var name = baseName;
var nameLowerCase = name.ToLower();
var nameIsUnique = false;
var namesTried = 1;

Expand All @@ -351,10 +350,9 @@ public static string MakeUniqueName<TExisting>(string baseName, IEnumerable<TExi
foreach (var existing in existingSet)
{
var existingName = getNameFunc(existing);
if (existingName.ToLower() == nameLowerCase)
if (existingName.Equals(name, StringComparison.InvariantCultureIgnoreCase))
{
name = $"{baseName}{namesTried}";
nameLowerCase = name.ToLower();
nameIsUnique = false;
++namesTried;
break;
Expand Down