From e774734fd697f6741cb8c52f249f2f2f7adb2fad Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Mon, 29 Jul 2019 23:13:54 +0200 Subject: Use string[i] instead of GetChar(string, i) where appropriate --- DTFormatN.c | 12 ++++++------ DTTemplateFunctions.c | 14 +++++++------- DTUtility.c | 26 ++++++++++++-------------- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/DTFormatN.c b/DTFormatN.c index 37f604e..1556265 100644 --- a/DTFormatN.c +++ b/DTFormatN.c @@ -20,8 +20,8 @@ global func FormatN(string format, array placeholders, array items) for(var i = 0; i < GetLength(format); ++i) { - var c = GetChar(format, i); - if(c == 37) // % + var c = format[i]; + if(c == "%") { if(inPlaceholder == 0) { @@ -29,7 +29,7 @@ global func FormatN(string format, array placeholders, array items) } else if(inPlaceholder == 1) { - if(c == 37 && GetLength(placeholderType) == 0) // % + if(GetLength(placeholderType) == 0) { ret ..= "%"; inPlaceholder = 0; @@ -59,15 +59,15 @@ global func FormatN(string format, array placeholders, array items) { if(inPlaceholder == 0) { - ret = Format("%s%c", ret, c); + ret ..= c; } else if(inPlaceholder == 1) { - placeholderType = Format("%s%c", placeholderType, c); + placeholderType ..= c; } else if(inPlaceholder == 2) { - placeholderPart = Format("%s%c", placeholderPart, c); + placeholderPart ..= c; } } } diff --git a/DTTemplateFunctions.c b/DTTemplateFunctions.c index 6d8cd7e..e494766 100644 --- a/DTTemplateFunctions.c +++ b/DTTemplateFunctions.c @@ -76,10 +76,10 @@ global func Function(arguments, commands) var escapeCount = 0; for(var i = 0; i < GetLength(command); ++i) { - var c = GetChar(command, i); + var c = command[i]; if(isArg) { - if(c == 37) // % + if(c == "%") { if(argument == "") { @@ -102,7 +102,7 @@ global func Function(arguments, commands) } isArg = false; } - else if(argument == "" && c == 47) // / + else if(argument == "" && c == "/") { ++escapeCount; } @@ -114,22 +114,22 @@ global func Function(arguments, commands) contentPart = ""; } - argument = Format("%s%c", argument, c); + argument ..= c; } } else { - if(c == 37) // % + if(c == "%") { isArg = true; } - else if(c == 39) // ' + else if(c == "'") { contentPart ..= "\""; } else { - contentPart = Format("%s%c", contentPart, c); + contentPart ..= c; } } } diff --git a/DTUtility.c b/DTUtility.c index 2c1e952..5bf7ee9 100644 --- a/DTUtility.c +++ b/DTUtility.c @@ -49,18 +49,18 @@ global func EscapeString(string value) var ret = ""; for(var i = 0; i < GetLength(value); ++i) { - var c = GetChar(value, i); - if(c == 34) // " + var c = value[i]; + if(c == "\"") { ret ..= "\\\""; } - else if(c == 92) // \ + else if(c == "\\") { ret ..= "\\\\"; } else { - ret = Format("%s%c", ret, c); + ret ..= c; } } return ret; @@ -107,9 +107,6 @@ global func CreateBitField(string prefix, array flags) Log("%s%c%c", log, 10, 10); } -// pos >= 0 => begin at pos | pos < 0 => begin at GetLength(string) - pos -// count = 0 => replace all | count > 0 replace a maximum of count occurences from starting from pos - global func Lowercase(int c) { if((c >= 65 && c <= 90) || (c >= 192 && c <= 214) || (c >= 216 && c <= 221)) return c + 32; @@ -154,6 +151,8 @@ global func StringConcatenate(array strings) return ret; } +// pos >= 0 => begin at pos | pos < 0 => begin at GetLength(string) - pos +// count = 0 => replace all | count > 0 replace a maximum of count occurences starting from pos global func MultiStringReplace(find, strings, replace, bool caseInsensitive, int count, int pos, int maxpos) { var returnString = false; @@ -195,7 +194,7 @@ global func StringReplace(string find, string string, string replace, bool caseI for(var i = 0; i < pos; ++i) { - ret = Format("%s%c", ret, GetChar(string, i)); + ret ..= string[i]; } var match = 0; @@ -204,12 +203,11 @@ global func StringReplace(string find, string string, string replace, bool caseI for(i = pos; i + GetLength(find) - match - 1 < maxpos && count != 0; ++i) { - var c = GetChar(string, i); - if(CaseInsensitive(c, !caseInsensitive) == CaseInsensitive(GetChar(find, match), !caseInsensitive)) + if(CaseInsensitive(GetChar(string, i), !caseInsensitive) == CaseInsensitive(GetChar(find, match), !caseInsensitive)) { if(++match == GetLength(find)) { - ret = StringConcatenate([ret, replace]); + ret ..= replace; match = 0; --count; } @@ -220,17 +218,17 @@ global func StringReplace(string find, string string, string replace, bool caseI { for(var j = i - match; j < i; ++j) { - ret = Format("%s%c", ret, GetChar(string, j)); + ret ..= string[j]; } } match = 0; - ret = Format("%s%c", ret, GetChar(string, i)); + ret ..= string[i]; } } for(i -= match; i < GetLength(string); ++i) { - ret = Format("%s%c", ret, GetChar(string, i)); + ret ..= string[i]; } return ret; -- cgit v1.2.3-54-g00ecf