summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Fusik <piotr@fusion-lang.org>2024-02-22 15:25:17 +0100
committerPiotr Fusik <piotr@fusion-lang.org>2024-02-22 15:25:17 +0100
commit3c25bd27c8970d9c2c8479d564bee707982e2946 (patch)
treecfb23b689a5fd4f5253999379e579a4a4ab850ba
parenta496ee86488020946611a252a056471b770dd526 (diff)
[cpp] Fix warnings for string.ToLower/ToUpper.
#147
-rw-r--r--GenCpp.fu67
-rw-r--r--libfut.cpp64
-rw-r--r--libfut.cs68
-rw-r--r--libfut.hpp3
-rw-r--r--libfut.js67
5 files changed, 157 insertions, 112 deletions
diff --git a/GenCpp.fu b/GenCpp.fu
index c7e3482..c854929 100644
--- a/GenCpp.fu
+++ b/GenCpp.fu
@@ -23,7 +23,8 @@ public class GenCpp : GenCCpp
bool UsingStringViewLiterals;
bool HasEnumFlags;
bool StringReplace;
- bool StringToLowerUpper;
+ bool StringToLower;
+ bool StringToUpper;
protected override string GetTargetName() => "C++";
@@ -810,11 +811,11 @@ public class GenCpp : GenCCpp
WriteStringMethod(obj, "substr", method, args);
break;
case FuId.StringToLower:
- this.StringToLowerUpper = true;
+ this.StringToLower = true;
WriteCall("FuString_ToLower", obj);
break;
case FuId.StringToUpper:
- this.StringToLowerUpper = true;
+ this.StringToUpper = true;
WriteCall("FuString_ToUpper", obj);
break;
case FuId.ArrayBinarySearchAll:
@@ -1927,6 +1928,8 @@ public class GenCpp : GenCCpp
this.UsingStringViewLiterals = false;
this.HasEnumFlags = false;
this.StringReplace = false;
+ this.StringToLower = false;
+ this.StringToUpper = false;
OpenStringWriter();
OpenNamespace();
WriteRegexOptionsEnum(program);
@@ -1993,7 +1996,7 @@ public class GenCpp : GenCCpp
WriteCharLine('}');
CloseBlock();
}
- if (this.StringToLowerUpper) {
+ if (this.StringToLower || this.StringToUpper) {
WriteNewLine();
WriteLine("#if defined(_WIN32)");
WriteNewLine();
@@ -2025,7 +2028,7 @@ public class GenCpp : GenCCpp
WriteLine("\twide.length(), // cchSrc");
WriteLine("\t0, // lpDestStr");
WriteLine("\t0, // cchDest");
- WriteLine("\tNULL, NULL, NULL);");
+ WriteLine("\tNULL, NULL, 0);");
WriteLine("std::wstring strTo(sizeNeeded, 0);");
WriteLine("LCMapStringEx(");
WriteLine("\tLOCALE_NAME_SYSTEM_DEFAULT, // lpLocaleName");
@@ -2034,35 +2037,43 @@ public class GenCpp : GenCCpp
WriteLine("\twide.length(), // cchSrc");
WriteLine("\t&strTo[0], // lpDestStr");
WriteLine("\tsizeNeeded, // cchDest");
- WriteLine("\tNULL, NULL, NULL);");
+ WriteLine("\tNULL, NULL, 0);");
WriteLine("return FuString_WideToUtf8(strTo);");
CloseBlock();
- WriteNewLine();
- WriteLine("static std::string FuString_ToUpper(std::string_view str)");
- OpenBlock();
- WriteLine("\treturn FuString_Win32LCMap(std::string{ str }, LCMAP_UPPERCASE);");
- CloseBlock();
- WriteNewLine();
- WriteLine("static std::string FuString_ToLower(std::string_view str)");
- OpenBlock();
- WriteLine("\treturn FuString_Win32LCMap(std::string{ str }, LCMAP_LOWERCASE);");
- CloseBlock();
+ if (this.StringToLower) {
+ WriteNewLine();
+ WriteLine("static std::string FuString_ToLower(std::string_view str)");
+ OpenBlock();
+ WriteLine("\treturn FuString_Win32LCMap(std::string{ str }, LCMAP_LOWERCASE);");
+ CloseBlock();
+ }
+ if (this.StringToUpper) {
+ WriteNewLine();
+ WriteLine("static std::string FuString_ToUpper(std::string_view str)");
+ OpenBlock();
+ WriteLine("\treturn FuString_Win32LCMap(std::string{ str }, LCMAP_UPPERCASE);");
+ CloseBlock();
+ }
WriteNewLine();
WriteLine("#else");
WriteNewLine();
WriteLine("#include <unicode/unistr.h>");
- WriteNewLine();
- WriteLine("static std::string FuString_ToUpper(std::string_view str)");
- OpenBlock();
- WriteLine("\tstd::string result;");
- WriteLine("\treturn icu::UnicodeString::fromUTF8(s).toUpper().toUTF8String(result);");
- CloseBlock();
- WriteNewLine();
- WriteLine("static std::string FuString_ToLower(std::string_view str)");
- OpenBlock();
- WriteLine("\tstd::string result;");
- WriteLine("\treturn icu::UnicodeString::fromUTF8(s).toLower().toUTF8String(result);");
- CloseBlock();
+ if (this.StringToLower) {
+ WriteNewLine();
+ WriteLine("static std::string FuString_ToLower(std::string_view str)");
+ OpenBlock();
+ WriteLine("\tstd::string result;");
+ WriteLine("\treturn icu::UnicodeString::fromUTF8(s).toLower().toUTF8String(result);");
+ CloseBlock();
+ }
+ if (this.StringToUpper) {
+ WriteNewLine();
+ WriteLine("static std::string FuString_ToUpper(std::string_view str)");
+ OpenBlock();
+ WriteLine("\tstd::string result;");
+ WriteLine("\treturn icu::UnicodeString::fromUTF8(s).toUpper().toUTF8String(result);");
+ CloseBlock();
+ }
WriteNewLine();
WriteLine("#endif");
diff --git a/libfut.cpp b/libfut.cpp
index 69b34e7..f6f9fb2 100644
--- a/libfut.cpp
+++ b/libfut.cpp
@@ -13780,11 +13780,11 @@ void GenCpp::writeCallExpr(const FuExpr * obj, const FuMethod * method, const st
writeStringMethod(obj, "substr", method, args);
break;
case FuId::stringToLower:
- this->stringToLowerUpper = true;
+ this->stringToLower = true;
writeCall("FuString_ToLower", obj);
break;
case FuId::stringToUpper:
- this->stringToLowerUpper = true;
+ this->stringToUpper = true;
writeCall("FuString_ToUpper", obj);
break;
case FuId::arrayBinarySearchAll:
@@ -14882,6 +14882,8 @@ void GenCpp::writeProgram(const FuProgram * program)
this->usingStringViewLiterals = false;
this->hasEnumFlags = false;
this->stringReplace = false;
+ this->stringToLower = false;
+ this->stringToUpper = false;
openStringWriter();
openNamespace();
writeRegexOptionsEnum(program);
@@ -14945,7 +14947,7 @@ void GenCpp::writeProgram(const FuProgram * program)
writeCharLine('}');
closeBlock();
}
- if (this->stringToLowerUpper) {
+ if (this->stringToLower || this->stringToUpper) {
writeNewLine();
writeLine("#if defined(_WIN32)");
writeNewLine();
@@ -14977,7 +14979,7 @@ void GenCpp::writeProgram(const FuProgram * program)
writeLine("\twide.length(), // cchSrc");
writeLine("\t0, // lpDestStr");
writeLine("\t0, // cchDest");
- writeLine("\tNULL, NULL, NULL);");
+ writeLine("\tNULL, NULL, 0);");
writeLine("std::wstring strTo(sizeNeeded, 0);");
writeLine("LCMapStringEx(");
writeLine("\tLOCALE_NAME_SYSTEM_DEFAULT, // lpLocaleName");
@@ -14986,35 +14988,43 @@ void GenCpp::writeProgram(const FuProgram * program)
writeLine("\twide.length(), // cchSrc");
writeLine("\t&strTo[0], // lpDestStr");
writeLine("\tsizeNeeded, // cchDest");
- writeLine("\tNULL, NULL, NULL);");
+ writeLine("\tNULL, NULL, 0);");
writeLine("return FuString_WideToUtf8(strTo);");
closeBlock();
- writeNewLine();
- writeLine("static std::string FuString_ToUpper(std::string_view str)");
- openBlock();
- writeLine("\treturn FuString_Win32LCMap(std::string{ str }, LCMAP_UPPERCASE);");
- closeBlock();
- writeNewLine();
- writeLine("static std::string FuString_ToLower(std::string_view str)");
- openBlock();
- writeLine("\treturn FuString_Win32LCMap(std::string{ str }, LCMAP_LOWERCASE);");
- closeBlock();
+ if (this->stringToLower) {
+ writeNewLine();
+ writeLine("static std::string FuString_ToLower(std::string_view str)");
+ openBlock();
+ writeLine("\treturn FuString_Win32LCMap(std::string{ str }, LCMAP_LOWERCASE);");
+ closeBlock();
+ }
+ if (this->stringToUpper) {
+ writeNewLine();
+ writeLine("static std::string FuString_ToUpper(std::string_view str)");
+ openBlock();
+ writeLine("\treturn FuString_Win32LCMap(std::string{ str }, LCMAP_UPPERCASE);");
+ closeBlock();
+ }
writeNewLine();
writeLine("#else");
writeNewLine();
writeLine("#include <unicode/unistr.h>");
- writeNewLine();
- writeLine("static std::string FuString_ToUpper(std::string_view str)");
- openBlock();
- writeLine("\tstd::string result;");
- writeLine("\treturn icu::UnicodeString::fromUTF8(s).toUpper().toUTF8String(result);");
- closeBlock();
- writeNewLine();
- writeLine("static std::string FuString_ToLower(std::string_view str)");
- openBlock();
- writeLine("\tstd::string result;");
- writeLine("\treturn icu::UnicodeString::fromUTF8(s).toLower().toUTF8String(result);");
- closeBlock();
+ if (this->stringToLower) {
+ writeNewLine();
+ writeLine("static std::string FuString_ToLower(std::string_view str)");
+ openBlock();
+ writeLine("\tstd::string result;");
+ writeLine("\treturn icu::UnicodeString::fromUTF8(s).toLower().toUTF8String(result);");
+ closeBlock();
+ }
+ if (this->stringToUpper) {
+ writeNewLine();
+ writeLine("static std::string FuString_ToUpper(std::string_view str)");
+ openBlock();
+ writeLine("\tstd::string result;");
+ writeLine("\treturn icu::UnicodeString::fromUTF8(s).toUpper().toUTF8String(result);");
+ closeBlock();
+ }
writeNewLine();
writeLine("#endif");
}
diff --git a/libfut.cs b/libfut.cs
index 8d06782..6bae0ef 100644
--- a/libfut.cs
+++ b/libfut.cs
@@ -13353,7 +13353,9 @@ namespace Fusion
bool StringReplace;
- bool StringToLowerUpper;
+ bool StringToLower;
+
+ bool StringToUpper;
protected override string GetTargetName() => "C++";
@@ -14132,11 +14134,11 @@ namespace Fusion
WriteStringMethod(obj, "substr", method, args);
break;
case FuId.StringToLower:
- this.StringToLowerUpper = true;
+ this.StringToLower = true;
WriteCall("FuString_ToLower", obj);
break;
case FuId.StringToUpper:
- this.StringToLowerUpper = true;
+ this.StringToUpper = true;
WriteCall("FuString_ToUpper", obj);
break;
case FuId.ArrayBinarySearchAll:
@@ -15234,6 +15236,8 @@ namespace Fusion
this.UsingStringViewLiterals = false;
this.HasEnumFlags = false;
this.StringReplace = false;
+ this.StringToLower = false;
+ this.StringToUpper = false;
OpenStringWriter();
OpenNamespace();
WriteRegexOptionsEnum(program);
@@ -15297,7 +15301,7 @@ namespace Fusion
WriteCharLine('}');
CloseBlock();
}
- if (this.StringToLowerUpper) {
+ if (this.StringToLower || this.StringToUpper) {
WriteNewLine();
WriteLine("#if defined(_WIN32)");
WriteNewLine();
@@ -15329,7 +15333,7 @@ namespace Fusion
WriteLine("\twide.length(), // cchSrc");
WriteLine("\t0, // lpDestStr");
WriteLine("\t0, // cchDest");
- WriteLine("\tNULL, NULL, NULL);");
+ WriteLine("\tNULL, NULL, 0);");
WriteLine("std::wstring strTo(sizeNeeded, 0);");
WriteLine("LCMapStringEx(");
WriteLine("\tLOCALE_NAME_SYSTEM_DEFAULT, // lpLocaleName");
@@ -15338,35 +15342,43 @@ namespace Fusion
WriteLine("\twide.length(), // cchSrc");
WriteLine("\t&strTo[0], // lpDestStr");
WriteLine("\tsizeNeeded, // cchDest");
- WriteLine("\tNULL, NULL, NULL);");
+ WriteLine("\tNULL, NULL, 0);");
WriteLine("return FuString_WideToUtf8(strTo);");
CloseBlock();
- WriteNewLine();
- WriteLine("static std::string FuString_ToUpper(std::string_view str)");
- OpenBlock();
- WriteLine("\treturn FuString_Win32LCMap(std::string{ str }, LCMAP_UPPERCASE);");
- CloseBlock();
- WriteNewLine();
- WriteLine("static std::string FuString_ToLower(std::string_view str)");
- OpenBlock();
- WriteLine("\treturn FuString_Win32LCMap(std::string{ str }, LCMAP_LOWERCASE);");
- CloseBlock();
+ if (this.StringToLower) {
+ WriteNewLine();
+ WriteLine("static std::string FuString_ToLower(std::string_view str)");
+ OpenBlock();
+ WriteLine("\treturn FuString_Win32LCMap(std::string{ str }, LCMAP_LOWERCASE);");
+ CloseBlock();
+ }
+ if (this.StringToUpper) {
+ WriteNewLine();
+ WriteLine("static std::string FuString_ToUpper(std::string_view str)");
+ OpenBlock();
+ WriteLine("\treturn FuString_Win32LCMap(std::string{ str }, LCMAP_UPPERCASE);");
+ CloseBlock();
+ }
WriteNewLine();
WriteLine("#else");
WriteNewLine();
WriteLine("#include <unicode/unistr.h>");
- WriteNewLine();
- WriteLine("static std::string FuString_ToUpper(std::string_view str)");
- OpenBlock();
- WriteLine("\tstd::string result;");
- WriteLine("\treturn icu::UnicodeString::fromUTF8(s).toUpper().toUTF8String(result);");
- CloseBlock();
- WriteNewLine();
- WriteLine("static std::string FuString_ToLower(std::string_view str)");
- OpenBlock();
- WriteLine("\tstd::string result;");
- WriteLine("\treturn icu::UnicodeString::fromUTF8(s).toLower().toUTF8String(result);");
- CloseBlock();
+ if (this.StringToLower) {
+ WriteNewLine();
+ WriteLine("static std::string FuString_ToLower(std::string_view str)");
+ OpenBlock();
+ WriteLine("\tstd::string result;");
+ WriteLine("\treturn icu::UnicodeString::fromUTF8(s).toLower().toUTF8String(result);");
+ CloseBlock();
+ }
+ if (this.StringToUpper) {
+ WriteNewLine();
+ WriteLine("static std::string FuString_ToUpper(std::string_view str)");
+ OpenBlock();
+ WriteLine("\tstd::string result;");
+ WriteLine("\treturn icu::UnicodeString::fromUTF8(s).toUpper().toUTF8String(result);");
+ CloseBlock();
+ }
WriteNewLine();
WriteLine("#endif");
}
diff --git a/libfut.hpp b/libfut.hpp
index 88afc67..60375d8 100644
--- a/libfut.hpp
+++ b/libfut.hpp
@@ -2315,7 +2315,8 @@ private:
bool usingStringViewLiterals;
bool hasEnumFlags;
bool stringReplace;
- bool stringToLowerUpper;
+ bool stringToLower;
+ bool stringToUpper;
void startMethodCall(const FuExpr * obj);
void writeCamelCaseNotKeyword(std::string_view name);
void writeCollectionType(std::string_view name, const FuType * elementType);
diff --git a/libfut.js b/libfut.js
index 1f173d6..c03ce3a 100644
--- a/libfut.js
+++ b/libfut.js
@@ -13776,7 +13776,8 @@ export class GenCpp extends GenCCpp
#usingStringViewLiterals;
#hasEnumFlags;
#stringReplace;
- #stringToLowerUpper;
+ #stringToLower;
+ #stringToUpper;
getTargetName()
{
@@ -14563,11 +14564,11 @@ export class GenCpp extends GenCCpp
this.#writeStringMethod(obj, "substr", method, args);
break;
case FuId.STRING_TO_LOWER:
- this.#stringToLowerUpper = true;
+ this.#stringToLower = true;
this.writeCall("FuString_ToLower", obj);
break;
case FuId.STRING_TO_UPPER:
- this.#stringToLowerUpper = true;
+ this.#stringToUpper = true;
this.writeCall("FuString_ToUpper", obj);
break;
case FuId.ARRAY_BINARY_SEARCH_ALL:
@@ -15679,6 +15680,8 @@ export class GenCpp extends GenCCpp
this.#usingStringViewLiterals = false;
this.#hasEnumFlags = false;
this.#stringReplace = false;
+ this.#stringToLower = false;
+ this.#stringToUpper = false;
this.openStringWriter();
this.#openNamespace();
this.writeRegexOptionsEnum(program);
@@ -15743,7 +15746,7 @@ export class GenCpp extends GenCCpp
this.writeCharLine(125);
this.closeBlock();
}
- if (this.#stringToLowerUpper) {
+ if (this.#stringToLower || this.#stringToUpper) {
this.writeNewLine();
this.writeLine("#if defined(_WIN32)");
this.writeNewLine();
@@ -15775,7 +15778,7 @@ export class GenCpp extends GenCCpp
this.writeLine("\twide.length(), // cchSrc");
this.writeLine("\t0, // lpDestStr");
this.writeLine("\t0, // cchDest");
- this.writeLine("\tNULL, NULL, NULL);");
+ this.writeLine("\tNULL, NULL, 0);");
this.writeLine("std::wstring strTo(sizeNeeded, 0);");
this.writeLine("LCMapStringEx(");
this.writeLine("\tLOCALE_NAME_SYSTEM_DEFAULT, // lpLocaleName");
@@ -15784,35 +15787,43 @@ export class GenCpp extends GenCCpp
this.writeLine("\twide.length(), // cchSrc");
this.writeLine("\t&strTo[0], // lpDestStr");
this.writeLine("\tsizeNeeded, // cchDest");
- this.writeLine("\tNULL, NULL, NULL);");
+ this.writeLine("\tNULL, NULL, 0);");
this.writeLine("return FuString_WideToUtf8(strTo);");
this.closeBlock();
- this.writeNewLine();
- this.writeLine("static std::string FuString_ToUpper(std::string_view str)");
- this.openBlock();
- this.writeLine("\treturn FuString_Win32LCMap(std::string{ str }, LCMAP_UPPERCASE);");
- this.closeBlock();
- this.writeNewLine();
- this.writeLine("static std::string FuString_ToLower(std::string_view str)");
- this.openBlock();
- this.writeLine("\treturn FuString_Win32LCMap(std::string{ str }, LCMAP_LOWERCASE);");
- this.closeBlock();
+ if (this.#stringToLower) {
+ this.writeNewLine();
+ this.writeLine("static std::string FuString_ToLower(std::string_view str)");
+ this.openBlock();
+ this.writeLine("\treturn FuString_Win32LCMap(std::string{ str }, LCMAP_LOWERCASE);");
+ this.closeBlock();
+ }
+ if (this.#stringToUpper) {
+ this.writeNewLine();
+ this.writeLine("static std::string FuString_ToUpper(std::string_view str)");
+ this.openBlock();
+ this.writeLine("\treturn FuString_Win32LCMap(std::string{ str }, LCMAP_UPPERCASE);");
+ this.closeBlock();
+ }
this.writeNewLine();
this.writeLine("#else");
this.writeNewLine();
this.writeLine("#include <unicode/unistr.h>");
- this.writeNewLine();
- this.writeLine("static std::string FuString_ToUpper(std::string_view str)");
- this.openBlock();
- this.writeLine("\tstd::string result;");
- this.writeLine("\treturn icu::UnicodeString::fromUTF8(s).toUpper().toUTF8String(result);");
- this.closeBlock();
- this.writeNewLine();
- this.writeLine("static std::string FuString_ToLower(std::string_view str)");
- this.openBlock();
- this.writeLine("\tstd::string result;");
- this.writeLine("\treturn icu::UnicodeString::fromUTF8(s).toLower().toUTF8String(result);");
- this.closeBlock();
+ if (this.#stringToLower) {
+ this.writeNewLine();
+ this.writeLine("static std::string FuString_ToLower(std::string_view str)");
+ this.openBlock();
+ this.writeLine("\tstd::string result;");
+ this.writeLine("\treturn icu::UnicodeString::fromUTF8(s).toLower().toUTF8String(result);");
+ this.closeBlock();
+ }
+ if (this.#stringToUpper) {
+ this.writeNewLine();
+ this.writeLine("static std::string FuString_ToUpper(std::string_view str)");
+ this.openBlock();
+ this.writeLine("\tstd::string result;");
+ this.writeLine("\treturn icu::UnicodeString::fromUTF8(s).toUpper().toUTF8String(result);");
+ this.closeBlock();
+ }
this.writeNewLine();
this.writeLine("#endif");
}