AcManager.Tools.SemiGui.VariablesReplacement.Process C# (CSharp) Method

Process() public static method

public static Process ( [ str, [ startProperties, [ result ) : string
str [
startProperties [
result [
return string
        public static string Process([NotNull] string str, [NotNull] Game.StartProperties startProperties, [CanBeNull] Game.Result result) {
            if (startProperties == null) throw new ArgumentNullException(nameof(startProperties));
            if (str == null) throw new ArgumentNullException(nameof(str));

            return ReplayNameRegex.Replace(str, match => {
                var value = GetValue(startProperties, result, match.Groups[1].Value)?.Trim();
                if (string.IsNullOrEmpty(value)) return "-";

                foreach (var c in match.Groups[2].Success ? match.Groups[2].Value.ToLowerInvariant() : string.Empty) {
                    switch (c) {
                        case 'l':
                            value = value.ToLowerInvariant();
                            break;

                        case 'u':
                            value = value.ToUpperInvariant();
                            break;

                        case '0':
                            value = value.Substring(0, 1);
                            break;

                        default:
                            Logging.Warning("Unsupported modifier: " + c);
                            break;
                    }
                }

                return value;
            });
        }
    }

Usage Example

Esempio n. 1
0
        private static string GetReplayName([CanBeNull] Game.StartProperties startProperties, [CanBeNull] Game.Result result)
        {
            if (startProperties == null)
            {
                return($"_autosave_{DateTime.Now.ToMillisecondsTimestamp()}.acreplay");
            }

            var s = SettingsHolder.Drive.ReplaysNameFormat;

            if (string.IsNullOrEmpty(s))
            {
                s = SettingsHolder.Drive.DefaultReplaysNameFormat;
            }

            return(FileUtils.EnsureFileNameIsValid(VariablesReplacement.Process(s, startProperties, result)));
        }