diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 2231a6a..52a4910 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -35,7 +35,7 @@ jobs:
- name: Pull Assets
run: |
- git clone https://${{ secrets.ACCESS_TOKEN_GITHUB }}@github.com/imas-tools/gakumas-raw-txts.git app/src/main/assets/gakumas-local/gakumas-raw-txts
+ git clone https://${{ secrets.ACCESS_TOKEN_GITHUB }}@github.com/DreamGallery/Campus-adv-txts.git app/src/main/assets/gakumas-local/gakumas-raw-txts
mv app/src/main/assets/gakumas-local/gakumas-raw-txts/Resource app/src/main/assets/gakumas-local/raw
rm -rf app/src/main/assets/gakumas-local/gakumas-raw-txts
continue-on-error: true
diff --git a/app/build.gradle b/app/build.gradle
index 50218fb..a58605c 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -3,6 +3,7 @@ plugins {
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.serialization)
+ id("kotlin-parcelize")
}
android {
@@ -14,8 +15,8 @@ android {
applicationId "io.github.chinosk.gakumas.localify"
minSdk 29
targetSdk 34
- versionCode 2
- versionName "v1.2"
+ versionCode 4
+ versionName "v1.6"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
@@ -75,6 +76,7 @@ android {
mergeAssetsTask.doLast {
delete(fileTree(dir: mergeAssetsTask.outputDir, includes: ['gakumas-local/gakuen-adapted-translation-data/**',
'gakumas-local/GakumasPreTranslation/**',
+ 'gakumas-local/gakumas-generic-strings-translation/**',
'gakumas-local/raw/**']))
}
}
@@ -82,6 +84,9 @@ android {
}
dependencies {
+ // implementation files('libs/lspatch_cleaned.jar')
+ // api 'com.google.guava:guava:32.0.1-jre'
+
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.material3)
@@ -90,6 +95,14 @@ dependencies {
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.navigation.compose)
+ implementation files('libs/lspatch_cleaned.jar')
+
+ implementation(libs.zip4j)
+ implementation(libs.shizukuApi)
+ implementation(libs.rikka.shizuku.provider)
+ implementation(libs.rikka.refine)
+ implementation(libs.rikka.hidden.stub)
+ implementation(libs.hiddenapibypass)
def composeBom = platform(libs.androidx.compose.bom)
implementation(composeBom)
diff --git a/app/libs/lspatch.jar b/app/libs/lspatch.jar
new file mode 100644
index 0000000..5c926ad
Binary files /dev/null and b/app/libs/lspatch.jar differ
diff --git a/app/libs/lspatch_cleaned.jar b/app/libs/lspatch_cleaned.jar
new file mode 100644
index 0000000..3d2a7b3
Binary files /dev/null and b/app/libs/lspatch_cleaned.jar differ
diff --git a/app/libs/make_lspatch_cleaned_steps.txt b/app/libs/make_lspatch_cleaned_steps.txt
new file mode 100644
index 0000000..f1c2878
--- /dev/null
+++ b/app/libs/make_lspatch_cleaned_steps.txt
@@ -0,0 +1,6 @@
+jar xf lspatch.jar
+cp -r assets/lspatch/so ../../src/main/assets/lspatch/so
+rm -rf com/google/common/util/concurrent
+rm -rf com/google/errorprone/annotations
+python rm_duplicate.py
+jar cf lspatch_cleaned.jar .
diff --git a/app/libs/rm_duplicate.py b/app/libs/rm_duplicate.py
new file mode 100644
index 0000000..3887a73
--- /dev/null
+++ b/app/libs/rm_duplicate.py
@@ -0,0 +1,45 @@
+import os
+
+
+logs = """
+Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules listenablefuture-1.0.jar -> listenablefuture-1.0 (com.google.guava:listenablefuture:1.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.CanIgnoreReturnValue found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.CheckReturnValue found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.CompatibleWith found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.CompileTimeConstant found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.DoNotCall found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.DoNotMock found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.ForOverride found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.FormatMethod found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.FormatString found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.Immutable found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.IncompatibleModifiers found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.InlineMe found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.InlineMeValidationDisabled found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.Keep found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.Modifier found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.MustBeClosed found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.NoAllocation found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.OverridingMethodsMustInvokeSuper found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.RequiredModifiers found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.RestrictedApi found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.SuppressPackageLocation found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.Var found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.concurrent.GuardedBy found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.concurrent.LazyInit found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.concurrent.LockMethod found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+Duplicate class com.google.errorprone.annotations.concurrent.UnlockMethod found in modules error_prone_annotations-2.15.0.jar -> error_prone_annotations-2.15.0 (com.google.errorprone:error_prone_annotations:2.15.0) and lspatch.jar -> lspatch (lspatch.jar)
+"""
+
+for i in logs.split("\n"):
+ if i.startswith("Duplicate class "):
+ flag_pos = i.find(" found in modules")
+ if flag_pos == -1:
+ continue
+ class_name = i[len("Duplicate class "):flag_pos]
+ file_name = class_name.replace(".", "/") + ".class"
+ if not os.path.isfile(file_name):
+ print(file_name, "not found!!!")
+ else:
+ os.remove(file_name)
+ print(file_name, "removed.")
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 5833422..4fb3e7e 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -3,6 +3,9 @@
xmlns:tools="http://schemas.android.com/tools">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/assets/about_contributors_zh_cn.json b/app/src/main/assets/about_contributors_zh_cn.json
index d825d11..aed9b8a 100644
--- a/app/src/main/assets/about_contributors_zh_cn.json
+++ b/app/src/main/assets/about_contributors_zh_cn.json
@@ -24,6 +24,10 @@
],
"contrib_img": {
"plugin": "https://contrib.rocks/image?repo=chinosk6/gakuen-imas-localify",
- "translation": "https://contrib.rocks/image?repo=chinosk6/GakumasTranslationData"
+ "translation": "https://contrib.rocks/image?repo=chinosk6/GakumasTranslationData",
+ "translations": [
+ "https://contrib.rocks/image?repo=imas-tools/gakuen-adapted-translation-data",
+ "https://contrib.rocks/image?repo=imas-tools/gakumas-generic-strings-translation"
+ ]
}
}
\ No newline at end of file
diff --git a/app/src/main/assets/gakumas-local b/app/src/main/assets/gakumas-local
index a60a171..ee4fb90 160000
--- a/app/src/main/assets/gakumas-local
+++ b/app/src/main/assets/gakumas-local
@@ -1 +1 @@
-Subproject commit a60a171b40b22b04d567ab39a8fd7f571c7921f5
+Subproject commit ee4fb90f37cf2bbeb5744a4735071473f2c5635d
diff --git a/app/src/main/assets/lspatch/so/arm64-v8a/liblspatch.so b/app/src/main/assets/lspatch/so/arm64-v8a/liblspatch.so
new file mode 100644
index 0000000..556ad7d
Binary files /dev/null and b/app/src/main/assets/lspatch/so/arm64-v8a/liblspatch.so differ
diff --git a/app/src/main/assets/lspatch/so/armeabi-v7a/liblspatch.so b/app/src/main/assets/lspatch/so/armeabi-v7a/liblspatch.so
new file mode 100644
index 0000000..32ddd9e
Binary files /dev/null and b/app/src/main/assets/lspatch/so/armeabi-v7a/liblspatch.so differ
diff --git a/app/src/main/assets/lspatch/so/x86/liblspatch.so b/app/src/main/assets/lspatch/so/x86/liblspatch.so
new file mode 100644
index 0000000..68201ae
Binary files /dev/null and b/app/src/main/assets/lspatch/so/x86/liblspatch.so differ
diff --git a/app/src/main/assets/lspatch/so/x86_64/liblspatch.so b/app/src/main/assets/lspatch/so/x86_64/liblspatch.so
new file mode 100644
index 0000000..e8d140e
Binary files /dev/null and b/app/src/main/assets/lspatch/so/x86_64/liblspatch.so differ
diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt
index 0a478b0..8f3f600 100644
--- a/app/src/main/cpp/CMakeLists.txt
+++ b/app/src/main/cpp/CMakeLists.txt
@@ -45,6 +45,7 @@ add_library(${CMAKE_PROJECT_NAME} SHARED
GakumasLocalify/camera/baseCamera.cpp
GakumasLocalify/camera/camera.cpp
GakumasLocalify/config/Config.cpp
+ GakumasLocalify/string_parser/StringParser.cpp
)
target_link_libraries(${CMAKE_PROJECT_NAME} xdl::xdl)
@@ -53,12 +54,17 @@ target_link_libraries(${CMAKE_PROJECT_NAME} shadowhook::shadowhook)
include_directories(GakumasLocalify)
include_directories(${CMAKE_SOURCE_DIR}/deps)
+set(FMT_DIR "${CMAKE_SOURCE_DIR}/deps/fmt-11.0.2")
+include_directories(${FMT_DIR}/include)
+add_library(fmt STATIC ${FMT_DIR}/src/format.cc)
+
# Specifies libraries CMake should link to your target library. You
# can link libraries from various origins, such as libraries defined in this
# build script, prebuilt third-party libraries, or Android system libraries.
target_link_libraries(${CMAKE_PROJECT_NAME}
# List libraries link to the target library
android
- log)
+ log
+ fmt)
target_compile_features(${CMAKE_PROJECT_NAME} PRIVATE cxx_std_23)
diff --git a/app/src/main/cpp/GakumasLocalify/Hook.cpp b/app/src/main/cpp/GakumasLocalify/Hook.cpp
index 34852ef..75b1628 100644
--- a/app/src/main/cpp/GakumasLocalify/Hook.cpp
+++ b/app/src/main/cpp/GakumasLocalify/Hook.cpp
@@ -333,6 +333,13 @@ namespace GakumasLocal::HookMain {
"TMPro", "TMP_Text", "get_font");
static auto set_font = Il2cppUtils::GetMethod("Unity.TextMeshPro.dll",
"TMPro", "TMP_Text", "set_font");
+// static auto set_fontMaterial = Il2cppUtils::GetMethod("Unity.TextMeshPro.dll",
+// "TMPro", "TMP_Text", "set_fontMaterial");
+// static auto ForceMeshUpdate = Il2cppUtils::GetMethod("Unity.TextMeshPro.dll",
+// "TMPro", "TMP_Text", "ForceMeshUpdate");
+//
+// static auto get_material = Il2cppUtils::GetMethod("Unity.TextMeshPro.dll",
+// "TMPro", "TMP_Asset", "get_material");
static auto set_sourceFontFile = Il2cppUtils::GetMethod("Unity.TextMeshPro.dll", "TMPro",
"TMP_FontAsset", "set_sourceFontFile");
@@ -351,6 +358,10 @@ namespace GakumasLocal::HookMain {
if (updatedFontPtrs.size() > 200) updatedFontPtrs.clear();
}
set_font->Invoke(TMP_Textself, fontAsset);
+
+// auto fontMaterial = get_material->Invoke(fontAsset);
+// set_fontMaterial->Invoke(TMP_Textself, fontMaterial);
+// ForceMeshUpdate->Invoke(TMP_Textself, false, false);
}
DEFINE_HOOK(void, TMP_Text_PopulateTextBackingArray, (void* self, UnityResolve::UnityType::String* text, int start, int length)) {
@@ -365,6 +376,7 @@ namespace GakumasLocal::HookMain {
std::string transText;
if (Local::GetGenericText(origText, &transText)) {
const auto newText = UnityResolve::UnityType::String::New(transText);
+ UpdateFont(self);
return TMP_Text_PopulateTextBackingArray_Orig(self, newText, 0, newText->length);
}
diff --git a/app/src/main/cpp/GakumasLocalify/Local.cpp b/app/src/main/cpp/GakumasLocalify/Local.cpp
index f0debeb..fd9e170 100644
--- a/app/src/main/cpp/GakumasLocalify/Local.cpp
+++ b/app/src/main/cpp/GakumasLocalify/Local.cpp
@@ -15,6 +15,7 @@
#include
#include
#include "BaseDefine.h"
+#include "string_parser/StringParser.hpp"
namespace GakumasLocal::Local {
@@ -22,9 +23,12 @@ namespace GakumasLocal::Local {
std::unordered_map i18nDumpData{};
std::unordered_map genericText{};
std::unordered_map genericSplitText{};
+ std::unordered_map genericFmtText{};
std::vector genericTextDumpData{};
std::vector genericSplittedDumpData{};
std::vector genericOrigTextDumpData{};
+ std::vector genericFmtTextDumpData{};
+
std::unordered_set translatedText{};
int genericDumpFileIndex = 0;
const std::string splitTextPrefix = "[__split__]";
@@ -64,7 +68,8 @@ namespace GakumasLocal::Local {
enum class DumpStrStat {
DEFAULT = 0,
SPLITTABLE_ORIG = 1,
- SPLITTED = 2
+ SPLITTED = 2,
+ FMT = 3
};
enum class SplitTagsTranslationStat {
@@ -262,6 +267,15 @@ namespace GakumasLocal::Local {
return ret;
}
+ void ReplaceNumberComma(std::string* orig) {
+ if (!orig->contains(",")) return;
+ std::string newStr = *orig;
+ ReplaceString(&newStr, ",", ",");
+ if (IsPureStringValue(newStr)) {
+ *orig = newStr;
+ }
+ }
+
SplitTagsTranslationStat GetSplitTagsTranslationFull(const std::string& origTextIn, std::string* newText, std::vector& unTransResultRet) {
// static const std::u16string splitFlags = u"0123456789++--%%【】.";
static const std::unordered_set splitFlags = {u'0', u'1', u'2', u'3', u'4', u'5',
@@ -306,7 +320,9 @@ namespace GakumasLocal::Local {
return SplitTagsTranslationStat::NO_SPLIT_AND_EMPTY;
}
else {
- return SplitTagsTranslationStat::NO_SPLIT;
+ if (!(!origText.empty() && splitFlags.contains(origText[0]))) { // 开头为特殊符号或数字
+ return SplitTagsTranslationStat::NO_SPLIT;
+ }
}
}
checkCurrentWaitingReplaceTextAndClear()
@@ -317,8 +333,9 @@ namespace GakumasLocal::Local {
bool hasNotTrans = false;
if (!waitingReplaceTexts.empty()) {
for (const auto& i : waitingReplaceTexts) {
- const auto searchResult = findInMapIgnoreSpace(i, genericSplitText);
+ std::string searchResult = findInMapIgnoreSpace(i, genericSplitText);
if (!searchResult.empty()) {
+ ReplaceNumberComma(&searchResult);
ReplaceString(newText, i, searchResult);
hasTrans = true;
}
@@ -358,6 +375,7 @@ namespace GakumasLocal::Local {
LoadJsonDataToMap(genericFile, genericText, true, true, true);
genericSplitText.clear();
+ genericFmtText.clear();
LoadJsonDataToMap(genericSplitFile, genericSplitText, true, true, true);
if (std::filesystem::exists(genericDir) || std::filesystem::is_directory(genericDir)) {
for (const auto& entry : std::filesystem::recursive_directory_iterator(genericDir)) {
@@ -367,6 +385,9 @@ namespace GakumasLocal::Local {
if (currFile.filename().string().ends_with(".split.json")) { // split text file
LoadJsonDataToMap(currFile, genericSplitText, true, false, true);
}
+ if (currFile.filename().string().ends_with(".fmt.json")) { // fmt text file
+ LoadJsonDataToMap(currFile, genericFmtText, true, false, false);
+ }
else {
LoadJsonDataToMap(currFile, genericText, true, false, true);
}
@@ -442,6 +463,10 @@ namespace GakumasLocal::Local {
if (genericDumpFileIndex == 0) return "generic_orig.json";
return Log::StringFormat("generic_orig_%d.json", genericDumpFileIndex);
}
+ else if (stat == DumpStrStat::FMT) {
+ if (genericDumpFileIndex == 0) return "generic.fmt.json";
+ return Log::StringFormat("generic_%d.fmt.json", genericDumpFileIndex);
+ }
else {
if (genericDumpFileIndex == 0) return "generic.json";
return Log::StringFormat("generic_%d.json", genericDumpFileIndex);
@@ -452,10 +477,11 @@ namespace GakumasLocal::Local {
void DumpGenericText(const std::string& origText, DumpStrStat stat = DumpStrStat::DEFAULT) {
if (translatedText.contains(origText)) return;
- std::array>, 3> targets = {
+ std::array>, 4> targets = {
genericTextDumpData,
genericOrigTextDumpData,
- genericSplittedDumpData
+ genericSplittedDumpData,
+ genericFmtTextDumpData
};
auto& appendTarget = targets[static_cast(stat)].get();
@@ -475,25 +501,50 @@ namespace GakumasLocal::Local {
DumpVectorDataToJson(dumpBasePath, GetDumpGenericFileName(DumpStrStat::DEFAULT), genericTextDumpData);
DumpVectorDataToJson(dumpBasePath, GetDumpGenericFileName(DumpStrStat::SPLITTABLE_ORIG), genericOrigTextDumpData);
DumpVectorDataToJson(dumpBasePath, GetDumpGenericFileName(DumpStrStat::SPLITTED), genericSplittedDumpData, splitTextPrefix);
+ DumpVectorDataToJson(dumpBasePath, GetDumpGenericFileName(DumpStrStat::FMT), genericFmtTextDumpData);
genericTextDumpData.clear();
genericSplittedDumpData.clear();
genericOrigTextDumpData.clear();
+ genericFmtTextDumpData.clear();
inDumpGeneric = false;
}).detach();
}
bool GetGenericText(const std::string& origText, std::string* newStr) {
+ // 完全匹配
if (const auto iter = genericText.find(origText); iter != genericText.end()) {
*newStr = iter->second;
return true;
}
+ // 不翻译翻译过的文本
+ if (translatedText.contains(origText)) {
+ return false;
+ }
+
+ // fmt 文本
+ auto fmtText = StringParser::ParseItems::parse(origText, false);
+ if (fmtText.isValid) {
+ const auto fmtStr = fmtText.ToFmtString();
+ if (auto it = genericFmtText.find(fmtStr); it != genericFmtText.end()) {
+ auto newRet = fmtText.MergeText(it->second);
+ if (!newRet.empty()) {
+ *newStr = newRet;
+ return true;
+ }
+ }
+ if (Config::dumpText) {
+ DumpGenericText(fmtStr, DumpStrStat::FMT);
+ }
+ }
auto ret = false;
+ // 分割匹配
std::vector unTransResultRet;
const auto splitTransStat = GetSplitTagsTranslationFull(origText, newStr, unTransResultRet);
switch (splitTransStat) {
case SplitTagsTranslationStat::FULL_TRANS: {
+ DumpGenericText(origText, DumpStrStat::SPLITTABLE_ORIG);
return true;
} break;
diff --git a/app/src/main/cpp/GakumasLocalify/Misc.cpp b/app/src/main/cpp/GakumasLocalify/Misc.cpp
index 1ac4204..5202a32 100644
--- a/app/src/main/cpp/GakumasLocalify/Misc.cpp
+++ b/app/src/main/cpp/GakumasLocalify/Misc.cpp
@@ -3,6 +3,7 @@
#include
#include
#include
+#include "fmt/core.h"
extern JavaVM* g_javaVM;
@@ -88,11 +89,85 @@ namespace GakumasLocal::Misc {
int CSEnum::GetValueByName(const std::string &name) {
for (int i = 0; i < names.size(); i++) {
- if (names[i].compare(name) == 0) {
+ if (names[i] == name) {
return values[i];
}
}
return values[0];
}
+
+ namespace StringFormat {
+ template
+ std::string string_format(const std::string& fmt, Args&&... args) {
+ // return std::vformat(fmt, std::make_format_args(std::forward(args)...));
+ return fmt::format(fmt::runtime(fmt), std::forward(args)...);
+ }
+
+
+ template
+ auto vectorToTupleImpl(const std::vector& vec, std::index_sequence) {
+ if (vec.size() != N) {
+ // printf("vec.size: %zu, N: %zu\n", vec.size(), N);
+ throw std::out_of_range("Vector size does not match tuple size.");
+ }
+ return std::make_tuple(vec[Indices]...);
+ }
+
+ template
+ auto vectorToTuple(const std::vector& vec) {
+ return vectorToTupleImpl(vec, std::make_index_sequence{});
+ }
+
+
+ template
+ std::string stringFormat(const std::string& fmt, const std::vector& vec) {
+ std::string ret = fmt;
+
+#define CASE_ARG_COUNT(N) \
+ case N: {\
+ auto tp = vectorToTuple(vec); \
+ std::apply([&](auto&&... args) { \
+ ret = string_format(fmt, args...); \
+ }, tp); } break;
+
+ switch (vec.size()) {
+ CASE_ARG_COUNT(1)
+ CASE_ARG_COUNT(2)
+ CASE_ARG_COUNT(3)
+ CASE_ARG_COUNT(4)
+ CASE_ARG_COUNT(5)
+ CASE_ARG_COUNT(6)
+ CASE_ARG_COUNT(7)
+ CASE_ARG_COUNT(8)
+ CASE_ARG_COUNT(9)
+ CASE_ARG_COUNT(10)
+ CASE_ARG_COUNT(11)
+ CASE_ARG_COUNT(12)
+ CASE_ARG_COUNT(13)
+ CASE_ARG_COUNT(14)
+ CASE_ARG_COUNT(15)
+ CASE_ARG_COUNT(16)
+ CASE_ARG_COUNT(17)
+ CASE_ARG_COUNT(18)
+ CASE_ARG_COUNT(19)
+ CASE_ARG_COUNT(20)
+ CASE_ARG_COUNT(21)
+ CASE_ARG_COUNT(22)
+ CASE_ARG_COUNT(23)
+ CASE_ARG_COUNT(24)
+ }
+ return ret;
+ }
+
+ std::string stringFormatString(const std::string& fmt, const std::vector& vec) {
+ try {
+ return stringFormat(fmt, vec);
+ }
+ catch (std::exception& e) {
+ return fmt;
+ }
+ }
+ }
+
}
diff --git a/app/src/main/cpp/GakumasLocalify/Misc.hpp b/app/src/main/cpp/GakumasLocalify/Misc.hpp
index de3d15b..44ac4eb 100644
--- a/app/src/main/cpp/GakumasLocalify/Misc.hpp
+++ b/app/src/main/cpp/GakumasLocalify/Misc.hpp
@@ -73,5 +73,9 @@ namespace GakumasLocal {
size_t maxSize;
T sum;
};
+
+ namespace StringFormat {
+ std::string stringFormatString(const std::string& fmt, const std::vector& vec);
+ }
}
}
diff --git a/app/src/main/cpp/GakumasLocalify/string_parser/StringParser.cpp b/app/src/main/cpp/GakumasLocalify/string_parser/StringParser.cpp
new file mode 100644
index 0000000..3365537
--- /dev/null
+++ b/app/src/main/cpp/GakumasLocalify/string_parser/StringParser.cpp
@@ -0,0 +1,123 @@
+#include
+#include "StringParser.hpp"
+#include "fmt/core.h"
+#include "fmt/ranges.h"
+#include "../Misc.hpp"
+
+namespace StringParser {
+
+ std::string ParseItems::ToFmtString() {
+ std::vector ret{};
+ int currFlagIndex = 0;
+ for (const auto& i : items) {
+ if (i.type == ParseItemType::FLAG) {
+ ret.push_back(fmt::format("{{{}}}", currFlagIndex));
+ currFlagIndex++;
+ }
+ else {
+ ret.push_back(i.content);
+ }
+ }
+ return fmt::format("{}", fmt::join(ret, ""));
+ }
+
+ std::vector ParseItems::GetFlagValues() {
+ std::vector ret{};
+ for (const auto& i : items) {
+ if (i.type == ParseItemType::FLAG) {
+ ret.push_back(i.content);
+ }
+ }
+ return ret;
+ }
+
+ ParseItems ParseItems::parse(const std::string &str, bool parseTags) {
+ static const std::unordered_set splitFlags = {u'0', u'1', u'2', u'3', u'4', u'5',
+ u'6', u'7', u'8', u'9', u'+', u'+',
+ u'-', u'-', u'%', u'%',
+ u'.', u'×', u',', u','};
+
+ ParseItems result;
+ if (str.contains("{")) {
+ result.isValid = false;
+ return result;
+ }
+ std::u16string origText = GakumasLocal::Misc::ToUTF16(str);
+ bool isInTag = false;
+ bool isInFlagSequence = false;
+ std::u16string currentCacheText;
+
+ for (char16_t currChar : origText) {
+ if (parseTags && currChar == u'<') {
+ if (!currentCacheText.empty()) {
+ result.items.push_back({isInFlagSequence ? ParseItemType::FLAG : ParseItemType::TEXT,
+ GakumasLocal::Misc::ToUTF8(currentCacheText)});
+ currentCacheText.clear();
+ isInFlagSequence = false;
+ }
+ isInTag = true;
+ currentCacheText.push_back(currChar);
+ } else if (parseTags && currChar == u'>') {
+ isInTag = false;
+ currentCacheText.push_back(currChar);
+ result.items.push_back({ParseItemType::FLAG, GakumasLocal::Misc::ToUTF8(currentCacheText)});
+ currentCacheText.clear();
+ } else if (isInTag) {
+ currentCacheText.push_back(currChar);
+ } else if (splitFlags.contains(currChar)) {
+ if (!isInFlagSequence && !currentCacheText.empty()) {
+ result.items.push_back({ParseItemType::TEXT, GakumasLocal::Misc::ToUTF8(currentCacheText)});
+ currentCacheText.clear();
+ }
+ isInFlagSequence = true;
+ currentCacheText.push_back(currChar);
+ } else {
+ if (isInFlagSequence && !currentCacheText.empty()) {
+ result.items.push_back({ParseItemType::FLAG, GakumasLocal::Misc::ToUTF8(currentCacheText)});
+ currentCacheText.clear();
+ isInFlagSequence = false;
+ }
+ currentCacheText.push_back(currChar);
+ }
+ }
+
+ if (!currentCacheText.empty()) {
+ result.items.push_back({isInFlagSequence ? ParseItemType::FLAG : ParseItemType::TEXT,
+ GakumasLocal::Misc::ToUTF8(currentCacheText)});
+ }
+
+ for (auto& i : result.items) {
+ if (i.type == ParseItemType::FLAG) {
+ return result;
+ }
+ }
+ result.isValid = false;
+ return result;
+ }
+
+ std::string ParseItems::MergeText(ParseItems &textTarget, ParseItems &valueTarget) {
+ if (!textTarget.isValid) return "";
+ if (!valueTarget.isValid) return "";
+ const auto fmtText = textTarget.ToFmtString();
+ const auto values = valueTarget.GetFlagValues();
+ const std::string ret = GakumasLocal::Misc::StringFormat::stringFormatString(fmtText, values);
+ return {ret.begin(), ret.end()};
+ }
+
+ std::string ParseItems::MergeText(const std::string &newStr) {
+ if (!isValid) return "";
+ const auto values = GetFlagValues();
+ return GakumasLocal::Misc::StringFormat::stringFormatString(newStr, values);
+ }
+
+ int ParseItems::GetFlagCount() {
+ int ret = 0;
+ for (auto& i : items) {
+ if (i.type == ParseItemType::FLAG) {
+ ret++;
+ }
+ }
+ return ret;
+ }
+
+}
diff --git a/app/src/main/cpp/GakumasLocalify/string_parser/StringParser.hpp b/app/src/main/cpp/GakumasLocalify/string_parser/StringParser.hpp
new file mode 100644
index 0000000..aeb4268
--- /dev/null
+++ b/app/src/main/cpp/GakumasLocalify/string_parser/StringParser.hpp
@@ -0,0 +1,30 @@
+#pragma once
+
+#include
+#include
+
+namespace StringParser {
+ enum class ParseItemType {
+ FLAG,
+ TEXT
+ };
+
+ struct ParseItem {
+ ParseItemType type;
+ std::string content;
+ };
+
+ struct ParseItems {
+ bool isValid = true;
+ std::vector items;
+
+ std::string ToFmtString();
+ std::vector GetFlagValues();
+ std::string MergeText(const std::string& newStr);
+ int GetFlagCount();
+
+ static ParseItems parse(const std::string& str, bool parseTags);
+ static std::string MergeText(ParseItems& textTarget, ParseItems& valueTarget);
+ };
+
+}
diff --git a/app/src/main/cpp/deps/fmt-11.0.2/include/fmt/args.h b/app/src/main/cpp/deps/fmt-11.0.2/include/fmt/args.h
new file mode 100644
index 0000000..31a60e8
--- /dev/null
+++ b/app/src/main/cpp/deps/fmt-11.0.2/include/fmt/args.h
@@ -0,0 +1,228 @@
+// Formatting library for C++ - dynamic argument lists
+//
+// Copyright (c) 2012 - present, Victor Zverovich
+// All rights reserved.
+//
+// For the license information refer to format.h.
+
+#ifndef FMT_ARGS_H_
+#define FMT_ARGS_H_
+
+#ifndef FMT_MODULE
+# include // std::reference_wrapper
+# include // std::unique_ptr
+# include
+#endif
+
+#include "format.h" // std_string_view
+
+FMT_BEGIN_NAMESPACE
+
+namespace detail {
+
+template struct is_reference_wrapper : std::false_type {};
+template
+struct is_reference_wrapper> : std::true_type {};
+
+template auto unwrap(const T& v) -> const T& { return v; }
+template
+auto unwrap(const std::reference_wrapper& v) -> const T& {
+ return static_cast(v);
+}
+
+// node is defined outside dynamic_arg_list to workaround a C2504 bug in MSVC
+// 2022 (v17.10.0).
+//
+// Workaround for clang's -Wweak-vtables. Unlike for regular classes, for
+// templates it doesn't complain about inability to deduce single translation
+// unit for placing vtable. So node is made a fake template.
+template struct node {
+ virtual ~node() = default;
+ std::unique_ptr> next;
+};
+
+class dynamic_arg_list {
+ template struct typed_node : node<> {
+ T value;
+
+ template
+ FMT_CONSTEXPR typed_node(const Arg& arg) : value(arg) {}
+
+ template
+ FMT_CONSTEXPR typed_node(const basic_string_view& arg)
+ : value(arg.data(), arg.size()) {}
+ };
+
+ std::unique_ptr> head_;
+
+ public:
+ template auto push(const Arg& arg) -> const T& {
+ auto new_node = std::unique_ptr>(new typed_node(arg));
+ auto& value = new_node->value;
+ new_node->next = std::move(head_);
+ head_ = std::move(new_node);
+ return value;
+ }
+};
+} // namespace detail
+
+/**
+ * A dynamic list of formatting arguments with storage.
+ *
+ * It can be implicitly converted into `fmt::basic_format_args` for passing
+ * into type-erased formatting functions such as `fmt::vformat`.
+ */
+template
+class dynamic_format_arg_store
+#if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
+ // Workaround a GCC template argument substitution bug.
+ : public basic_format_args
+#endif
+{
+ private:
+ using char_type = typename Context::char_type;
+
+ template struct need_copy {
+ static constexpr detail::type mapped_type =
+ detail::mapped_type_constant::value;
+
+ enum {
+ value = !(detail::is_reference_wrapper::value ||
+ std::is_same>::value ||
+ std::is_same>::value ||
+ (mapped_type != detail::type::cstring_type &&
+ mapped_type != detail::type::string_type &&
+ mapped_type != detail::type::custom_type))
+ };
+ };
+
+ template
+ using stored_type = conditional_t<
+ std::is_convertible>::value &&
+ !detail::is_reference_wrapper::value,
+ std::basic_string, T>;
+
+ // Storage of basic_format_arg must be contiguous.
+ std::vector> data_;
+ std::vector> named_info_;
+
+ // Storage of arguments not fitting into basic_format_arg must grow
+ // without relocation because items in data_ refer to it.
+ detail::dynamic_arg_list dynamic_args_;
+
+ friend class basic_format_args;
+
+ auto get_types() const -> unsigned long long {
+ return detail::is_unpacked_bit | data_.size() |
+ (named_info_.empty()
+ ? 0ULL
+ : static_cast(detail::has_named_args_bit));
+ }
+
+ auto data() const -> const basic_format_arg* {
+ return named_info_.empty() ? data_.data() : data_.data() + 1;
+ }
+
+ template void emplace_arg(const T& arg) {
+ data_.emplace_back(detail::make_arg(arg));
+ }
+
+ template
+ void emplace_arg(const detail::named_arg& arg) {
+ if (named_info_.empty()) {
+ constexpr const detail::named_arg_info* zero_ptr{nullptr};
+ data_.insert(data_.begin(), {zero_ptr, 0});
+ }
+ data_.emplace_back(detail::make_arg(detail::unwrap(arg.value)));
+ auto pop_one = [](std::vector>* data) {
+ data->pop_back();
+ };
+ std::unique_ptr>, decltype(pop_one)>
+ guard{&data_, pop_one};
+ named_info_.push_back({arg.name, static_cast(data_.size() - 2u)});
+ data_[0].value_.named_args = {named_info_.data(), named_info_.size()};
+ guard.release();
+ }
+
+ public:
+ constexpr dynamic_format_arg_store() = default;
+
+ /**
+ * Adds an argument into the dynamic store for later passing to a formatting
+ * function.
+ *
+ * Note that custom types and string types (but not string views) are copied
+ * into the store dynamically allocating memory if necessary.
+ *
+ * **Example**:
+ *
+ * fmt::dynamic_format_arg_store store;
+ * store.push_back(42);
+ * store.push_back("abc");
+ * store.push_back(1.5f);
+ * std::string result = fmt::vformat("{} and {} and {}", store);
+ */
+ template void push_back(const T& arg) {
+ if (detail::const_check(need_copy::value))
+ emplace_arg(dynamic_args_.push>(arg));
+ else
+ emplace_arg(detail::unwrap(arg));
+ }
+
+ /**
+ * Adds a reference to the argument into the dynamic store for later passing
+ * to a formatting function.
+ *
+ * **Example**:
+ *
+ * fmt::dynamic_format_arg_store store;
+ * char band[] = "Rolling Stones";
+ * store.push_back(std::cref(band));
+ * band[9] = 'c'; // Changing str affects the output.
+ * std::string result = fmt::vformat("{}", store);
+ * // result == "Rolling Scones"
+ */
+ template void push_back(std::reference_wrapper arg) {
+ static_assert(
+ need_copy::value,
+ "objects of built-in types and string views are always copied");
+ emplace_arg(arg.get());
+ }
+
+ /**
+ * Adds named argument into the dynamic store for later passing to a
+ * formatting function. `std::reference_wrapper` is supported to avoid
+ * copying of the argument. The name is always copied into the store.
+ */
+ template
+ void push_back(const detail::named_arg& arg) {
+ const char_type* arg_name =
+ dynamic_args_.push>(arg.name).c_str();
+ if (detail::const_check(need_copy::value)) {
+ emplace_arg(
+ fmt::arg(arg_name, dynamic_args_.push>(arg.value)));
+ } else {
+ emplace_arg(fmt::arg(arg_name, arg.value));
+ }
+ }
+
+ /// Erase all elements from the store.
+ void clear() {
+ data_.clear();
+ named_info_.clear();
+ dynamic_args_ = detail::dynamic_arg_list();
+ }
+
+ /// Reserves space to store at least `new_cap` arguments including
+ /// `new_cap_named` named arguments.
+ void reserve(size_t new_cap, size_t new_cap_named) {
+ FMT_ASSERT(new_cap >= new_cap_named,
+ "Set of arguments includes set of named arguments");
+ data_.reserve(new_cap);
+ named_info_.reserve(new_cap_named);
+ }
+};
+
+FMT_END_NAMESPACE
+
+#endif // FMT_ARGS_H_
diff --git a/app/src/main/cpp/deps/fmt-11.0.2/include/fmt/base.h b/app/src/main/cpp/deps/fmt-11.0.2/include/fmt/base.h
new file mode 100644
index 0000000..6276494
--- /dev/null
+++ b/app/src/main/cpp/deps/fmt-11.0.2/include/fmt/base.h
@@ -0,0 +1,3077 @@
+// Formatting library for C++ - the base API for char/UTF-8
+//
+// Copyright (c) 2012 - present, Victor Zverovich
+// All rights reserved.
+//
+// For the license information refer to format.h.
+
+#ifndef FMT_BASE_H_
+#define FMT_BASE_H_
+
+#if defined(FMT_IMPORT_STD) && !defined(FMT_MODULE)
+# define FMT_MODULE
+#endif
+
+#ifndef FMT_MODULE
+# include // CHAR_BIT
+# include // FILE
+# include // strlen
+
+// is also included transitively from .
+# include // std::byte
+# include // std::enable_if
+#endif
+
+// The fmt library version in the form major * 10000 + minor * 100 + patch.
+#define FMT_VERSION 110002
+
+// Detect compiler versions.
+#if defined(__clang__) && !defined(__ibmxl__)
+# define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__)
+#else
+# define FMT_CLANG_VERSION 0
+#endif
+#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
+# define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
+#else
+# define FMT_GCC_VERSION 0
+#endif
+#if defined(__ICL)
+# define FMT_ICC_VERSION __ICL
+#elif defined(__INTEL_COMPILER)
+# define FMT_ICC_VERSION __INTEL_COMPILER
+#else
+# define FMT_ICC_VERSION 0
+#endif
+#if defined(_MSC_VER)
+# define FMT_MSC_VERSION _MSC_VER
+#else
+# define FMT_MSC_VERSION 0
+#endif
+
+// Detect standard library versions.
+#ifdef _GLIBCXX_RELEASE
+# define FMT_GLIBCXX_RELEASE _GLIBCXX_RELEASE
+#else
+# define FMT_GLIBCXX_RELEASE 0
+#endif
+#ifdef _LIBCPP_VERSION
+# define FMT_LIBCPP_VERSION _LIBCPP_VERSION
+#else
+# define FMT_LIBCPP_VERSION 0
+#endif
+
+#ifdef _MSVC_LANG
+# define FMT_CPLUSPLUS _MSVC_LANG
+#else
+# define FMT_CPLUSPLUS __cplusplus
+#endif
+
+// Detect __has_*.
+#ifdef __has_feature
+# define FMT_HAS_FEATURE(x) __has_feature(x)
+#else
+# define FMT_HAS_FEATURE(x) 0
+#endif
+#ifdef __has_include
+# define FMT_HAS_INCLUDE(x) __has_include(x)
+#else
+# define FMT_HAS_INCLUDE(x) 0
+#endif
+#ifdef __has_cpp_attribute
+# define FMT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
+#else
+# define FMT_HAS_CPP_ATTRIBUTE(x) 0
+#endif
+
+#define FMT_HAS_CPP14_ATTRIBUTE(attribute) \
+ (FMT_CPLUSPLUS >= 201402L && FMT_HAS_CPP_ATTRIBUTE(attribute))
+
+#define FMT_HAS_CPP17_ATTRIBUTE(attribute) \
+ (FMT_CPLUSPLUS >= 201703L && FMT_HAS_CPP_ATTRIBUTE(attribute))
+
+// Detect C++14 relaxed constexpr.
+#ifdef FMT_USE_CONSTEXPR
+// Use the provided definition.
+#elif FMT_GCC_VERSION >= 600 && FMT_CPLUSPLUS >= 201402L
+// GCC only allows throw in constexpr since version 6:
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67371.
+# define FMT_USE_CONSTEXPR 1
+#elif FMT_ICC_VERSION
+# define FMT_USE_CONSTEXPR 0 // https://github.com/fmtlib/fmt/issues/1628
+#elif FMT_HAS_FEATURE(cxx_relaxed_constexpr) || FMT_MSC_VERSION >= 1912
+# define FMT_USE_CONSTEXPR 1
+#else
+# define FMT_USE_CONSTEXPR 0
+#endif
+#if FMT_USE_CONSTEXPR
+# define FMT_CONSTEXPR constexpr
+#else
+# define FMT_CONSTEXPR
+#endif
+
+// Detect consteval, C++20 constexpr extensions and std::is_constant_evaluated.
+#if !defined(__cpp_lib_is_constant_evaluated)
+# define FMT_USE_CONSTEVAL 0
+#elif FMT_CPLUSPLUS < 201709L
+# define FMT_USE_CONSTEVAL 0
+#elif FMT_GLIBCXX_RELEASE && FMT_GLIBCXX_RELEASE < 10
+# define FMT_USE_CONSTEVAL 0
+#elif FMT_LIBCPP_VERSION && FMT_LIBCPP_VERSION < 10000
+# define FMT_USE_CONSTEVAL 0
+#elif defined(__apple_build_version__) && __apple_build_version__ < 14000029L
+# define FMT_USE_CONSTEVAL 0 // consteval is broken in Apple clang < 14.
+#elif FMT_MSC_VERSION && FMT_MSC_VERSION < 1929
+# define FMT_USE_CONSTEVAL 0 // consteval is broken in MSVC VS2019 < 16.10.
+#elif defined(__cpp_consteval)
+# define FMT_USE_CONSTEVAL 1
+#elif FMT_GCC_VERSION >= 1002 || FMT_CLANG_VERSION >= 1101
+# define FMT_USE_CONSTEVAL 1
+#else
+# define FMT_USE_CONSTEVAL 0
+#endif
+#if FMT_USE_CONSTEVAL
+# define FMT_CONSTEVAL consteval
+# define FMT_CONSTEXPR20 constexpr
+#else
+# define FMT_CONSTEVAL
+# define FMT_CONSTEXPR20
+#endif
+
+#if defined(FMT_USE_NONTYPE_TEMPLATE_ARGS)
+// Use the provided definition.
+#elif defined(__NVCOMPILER)
+# define FMT_USE_NONTYPE_TEMPLATE_ARGS 0
+#elif FMT_GCC_VERSION >= 903 && FMT_CPLUSPLUS >= 201709L
+# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1
+#elif defined(__cpp_nontype_template_args) && \
+ __cpp_nontype_template_args >= 201911L
+# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1
+#elif FMT_CLANG_VERSION >= 1200 && FMT_CPLUSPLUS >= 202002L
+# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1
+#else
+# define FMT_USE_NONTYPE_TEMPLATE_ARGS 0
+#endif
+
+#ifdef FMT_USE_CONCEPTS
+// Use the provided definition.
+#elif defined(__cpp_concepts)
+# define FMT_USE_CONCEPTS 1
+#else
+# define FMT_USE_CONCEPTS 0
+#endif
+
+// Check if exceptions are disabled.
+#ifdef FMT_EXCEPTIONS
+// Use the provided definition.
+#elif defined(__GNUC__) && !defined(__EXCEPTIONS)
+# define FMT_EXCEPTIONS 0
+#elif FMT_MSC_VERSION && !_HAS_EXCEPTIONS
+# define FMT_EXCEPTIONS 0
+#else
+# define FMT_EXCEPTIONS 1
+#endif
+#if FMT_EXCEPTIONS
+# define FMT_TRY try
+# define FMT_CATCH(x) catch (x)
+#else
+# define FMT_TRY if (true)
+# define FMT_CATCH(x) if (false)
+#endif
+
+#if FMT_HAS_CPP17_ATTRIBUTE(fallthrough)
+# define FMT_FALLTHROUGH [[fallthrough]]
+#elif defined(__clang__)
+# define FMT_FALLTHROUGH [[clang::fallthrough]]
+#elif FMT_GCC_VERSION >= 700 && \
+ (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= 520)
+# define FMT_FALLTHROUGH [[gnu::fallthrough]]
+#else
+# define FMT_FALLTHROUGH
+#endif
+
+// Disable [[noreturn]] on MSVC/NVCC because of bogus unreachable code warnings.
+#if FMT_HAS_CPP_ATTRIBUTE(noreturn) && !FMT_MSC_VERSION && !defined(__NVCC__)
+# define FMT_NORETURN [[noreturn]]
+#else
+# define FMT_NORETURN
+#endif
+
+#ifndef FMT_NODISCARD
+# if FMT_HAS_CPP17_ATTRIBUTE(nodiscard)
+# define FMT_NODISCARD [[nodiscard]]
+# else
+# define FMT_NODISCARD
+# endif
+#endif
+
+#ifdef FMT_DEPRECATED
+// Use the provided definition.
+#elif FMT_HAS_CPP14_ATTRIBUTE(deprecated)
+# define FMT_DEPRECATED [[deprecated]]
+#else
+# define FMT_DEPRECATED /* deprecated */
+#endif
+
+#ifdef FMT_INLINE
+// Use the provided definition.
+#elif FMT_GCC_VERSION || FMT_CLANG_VERSION
+# define FMT_ALWAYS_INLINE inline __attribute__((always_inline))
+#else
+# define FMT_ALWAYS_INLINE inline
+#endif
+// A version of FMT_INLINE to prevent code bloat in debug mode.
+#ifdef NDEBUG
+# define FMT_INLINE FMT_ALWAYS_INLINE
+#else
+# define FMT_INLINE inline
+#endif
+
+#if FMT_GCC_VERSION || FMT_CLANG_VERSION
+# define FMT_VISIBILITY(value) __attribute__((visibility(value)))
+#else
+# define FMT_VISIBILITY(value)
+#endif
+
+#ifndef FMT_GCC_PRAGMA
+// Workaround a _Pragma bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59884
+// and an nvhpc warning: https://github.com/fmtlib/fmt/pull/2582.
+# if FMT_GCC_VERSION >= 504 && !defined(__NVCOMPILER)
+# define FMT_GCC_PRAGMA(arg) _Pragma(arg)
+# else
+# define FMT_GCC_PRAGMA(arg)
+# endif
+#endif
+
+// GCC < 5 requires this-> in decltype.
+#if FMT_GCC_VERSION && FMT_GCC_VERSION < 500
+# define FMT_DECLTYPE_THIS this->
+#else
+# define FMT_DECLTYPE_THIS
+#endif
+
+#if FMT_MSC_VERSION
+# define FMT_MSC_WARNING(...) __pragma(warning(__VA_ARGS__))
+# define FMT_UNCHECKED_ITERATOR(It) \
+ using _Unchecked_type = It // Mark iterator as checked.
+#else
+# define FMT_MSC_WARNING(...)
+# define FMT_UNCHECKED_ITERATOR(It) using unchecked_type = It
+#endif
+
+#ifndef FMT_BEGIN_NAMESPACE
+# define FMT_BEGIN_NAMESPACE \
+ namespace fmt { \
+ inline namespace v11 {
+# define FMT_END_NAMESPACE \
+ } \
+ }
+#endif
+
+#ifndef FMT_EXPORT
+# define FMT_EXPORT
+# define FMT_BEGIN_EXPORT
+# define FMT_END_EXPORT
+#endif
+
+#if !defined(FMT_HEADER_ONLY) && defined(_WIN32)
+# if defined(FMT_LIB_EXPORT)
+# define FMT_API __declspec(dllexport)
+# elif defined(FMT_SHARED)
+# define FMT_API __declspec(dllimport)
+# endif
+#elif defined(FMT_LIB_EXPORT) || defined(FMT_SHARED)
+# define FMT_API FMT_VISIBILITY("default")
+#endif
+#ifndef FMT_API
+# define FMT_API
+#endif
+
+#ifndef FMT_UNICODE
+# define FMT_UNICODE 1
+#endif
+
+// Check if rtti is available.
+#ifndef FMT_USE_RTTI
+// __RTTI is for EDG compilers. _CPPRTTI is for MSVC.
+# if defined(__GXX_RTTI) || FMT_HAS_FEATURE(cxx_rtti) || defined(_CPPRTTI) || \
+ defined(__INTEL_RTTI__) || defined(__RTTI)
+# define FMT_USE_RTTI 1
+# else
+# define FMT_USE_RTTI 0
+# endif
+#endif
+
+#define FMT_FWD(...) static_cast(__VA_ARGS__)
+
+// Enable minimal optimizations for more compact code in debug mode.
+FMT_GCC_PRAGMA("GCC push_options")
+#if !defined(__OPTIMIZE__) && !defined(__CUDACC__)
+FMT_GCC_PRAGMA("GCC optimize(\"Og\")")
+#endif
+
+FMT_BEGIN_NAMESPACE
+
+// Implementations of enable_if_t and other metafunctions for older systems.
+template
+using enable_if_t = typename std::enable_if::type;
+template
+using conditional_t = typename std::conditional::type;
+template using bool_constant = std::integral_constant;
+template
+using remove_reference_t = typename std::remove_reference::type;
+template
+using remove_const_t = typename std::remove_const::type;
+template
+using remove_cvref_t = typename std::remove_cv>::type;
+template struct type_identity {
+ using type = T;
+};
+template using type_identity_t = typename type_identity::type;
+template
+using make_unsigned_t = typename std::make_unsigned::type;
+template
+using underlying_t = typename std::underlying_type::type;
+
+#if FMT_GCC_VERSION && FMT_GCC_VERSION < 500
+// A workaround for gcc 4.8 to make void_t work in a SFINAE context.
+template struct void_t_impl {
+ using type = void;
+};
+template using void_t = typename void_t_impl::type;
+#else
+template using void_t = void;
+#endif
+
+struct monostate {
+ constexpr monostate() {}
+};
+
+// An enable_if helper to be used in template parameters which results in much
+// shorter symbols: https://godbolt.org/z/sWw4vP. Extra parentheses are needed
+// to workaround a bug in MSVC 2019 (see #1140 and #1186).
+#ifdef FMT_DOC
+# define FMT_ENABLE_IF(...)
+#else
+# define FMT_ENABLE_IF(...) fmt::enable_if_t<(__VA_ARGS__), int> = 0
+#endif
+
+// This is defined in base.h instead of format.h to avoid injecting in std.
+// It is a template to avoid undesirable implicit conversions to std::byte.
+#ifdef __cpp_lib_byte
+template ::value)>
+inline auto format_as(T b) -> unsigned char {
+ return static_cast(b);
+}
+#endif
+
+namespace detail {
+// Suppresses "unused variable" warnings with the method described in
+// https://herbsutter.com/2009/10/18/mailbag-shutting-up-compiler-warnings/.
+// (void)var does not work on many Intel compilers.
+template FMT_CONSTEXPR void ignore_unused(const T&...) {}
+
+constexpr auto is_constant_evaluated(bool default_value = false) noexcept
+ -> bool {
+// Workaround for incompatibility between libstdc++ consteval-based
+// std::is_constant_evaluated() implementation and clang-14:
+// https://github.com/fmtlib/fmt/issues/3247.
+#if FMT_CPLUSPLUS >= 202002L && FMT_GLIBCXX_RELEASE >= 12 && \
+ (FMT_CLANG_VERSION >= 1400 && FMT_CLANG_VERSION < 1500)
+ ignore_unused(default_value);
+ return __builtin_is_constant_evaluated();
+#elif defined(__cpp_lib_is_constant_evaluated)
+ ignore_unused(default_value);
+ return std::is_constant_evaluated();
+#else
+ return default_value;
+#endif
+}
+
+// Suppresses "conditional expression is constant" warnings.
+template constexpr auto const_check(T value) -> T { return value; }
+
+FMT_NORETURN FMT_API void assert_fail(const char* file, int line,
+ const char* message);
+
+#if defined(FMT_ASSERT)
+// Use the provided definition.
+#elif defined(NDEBUG)
+// FMT_ASSERT is not empty to avoid -Wempty-body.
+# define FMT_ASSERT(condition, message) \
+ fmt::detail::ignore_unused((condition), (message))
+#else
+# define FMT_ASSERT(condition, message) \
+ ((condition) /* void() fails with -Winvalid-constexpr on clang 4.0.1 */ \
+ ? (void)0 \
+ : fmt::detail::assert_fail(__FILE__, __LINE__, (message)))
+#endif
+
+#ifdef FMT_USE_INT128
+// Do nothing.
+#elif defined(__SIZEOF_INT128__) && !defined(__NVCC__) && \
+ !(FMT_CLANG_VERSION && FMT_MSC_VERSION)
+# define FMT_USE_INT128 1
+using int128_opt = __int128_t; // An optional native 128-bit integer.
+using uint128_opt = __uint128_t;
+template inline auto convert_for_visit(T value) -> T {
+ return value;
+}
+#else
+# define FMT_USE_INT128 0
+#endif
+#if !FMT_USE_INT128
+enum class int128_opt {};
+enum class uint128_opt {};
+// Reduce template instantiations.
+template auto convert_for_visit(T) -> monostate { return {}; }
+#endif
+
+// Casts a nonnegative integer to unsigned.
+template
+FMT_CONSTEXPR auto to_unsigned(Int value) -> make_unsigned_t {
+ FMT_ASSERT(std::is_unsigned::value || value >= 0, "negative value");
+ return static_cast>(value);
+}
+
+// A heuristic to detect std::string and std::[experimental::]string_view.
+// It is mainly used to avoid dependency on <[experimental/]string_view>.
+template
+struct is_std_string_like : std::false_type {};
+template
+struct is_std_string_like().find_first_of(
+ typename T::value_type(), 0))>>
+ : std::is_convertible().data()),
+ const typename T::value_type*> {};
+
+// Returns true iff the literal encoding is UTF-8.
+constexpr auto is_utf8_enabled() -> bool {
+ // Avoid an MSVC sign extension bug: https://github.com/fmtlib/fmt/pull/2297.
+ using uchar = unsigned char;
+ return sizeof("\u00A7") == 3 && uchar("\u00A7"[0]) == 0xC2 &&
+ uchar("\u00A7"[1]) == 0xA7;
+}
+constexpr auto use_utf8() -> bool {
+ return !FMT_MSC_VERSION || is_utf8_enabled();
+}
+
+static_assert(!FMT_UNICODE || use_utf8(),
+ "Unicode support requires compiling with /utf-8");
+
+template FMT_CONSTEXPR auto length(const Char* s) -> size_t {
+ size_t len = 0;
+ while (*s++) ++len;
+ return len;
+}
+
+template
+FMT_CONSTEXPR auto compare(const Char* s1, const Char* s2, std::size_t n)
+ -> int {
+ if (!is_constant_evaluated() && sizeof(Char) == 1) return memcmp(s1, s2, n);
+ for (; n != 0; ++s1, ++s2, --n) {
+ if (*s1 < *s2) return -1;
+ if (*s1 > *s2) return 1;
+ }
+ return 0;
+}
+
+namespace adl {
+using namespace std;
+
+template
+auto invoke_back_inserter()
+ -> decltype(back_inserter(std::declval()));
+} // namespace adl
+
+template
+struct is_back_insert_iterator : std::false_type {};
+
+template
+struct is_back_insert_iterator<
+ It, bool_constant()),
+ It>::value>> : std::true_type {};
+
+// Extracts a reference to the container from *insert_iterator.
+template
+inline auto get_container(OutputIt it) -> typename OutputIt::container_type& {
+ struct accessor : OutputIt {
+ accessor(OutputIt base) : OutputIt(base) {}
+ using OutputIt::container;
+ };
+ return *accessor(it).container;
+}
+} // namespace detail
+
+// Checks whether T is a container with contiguous storage.
+template struct is_contiguous : std::false_type {};
+
+/**
+ * An implementation of `std::basic_string_view` for pre-C++17. It provides a
+ * subset of the API. `fmt::basic_string_view` is used for format strings even
+ * if `std::basic_string_view` is available to prevent issues when a library is
+ * compiled with a different `-std` option than the client code (which is not
+ * recommended).
+ */
+FMT_EXPORT
+template class basic_string_view {
+ private:
+ const Char* data_;
+ size_t size_;
+
+ public:
+ using value_type = Char;
+ using iterator = const Char*;
+
+ constexpr basic_string_view() noexcept : data_(nullptr), size_(0) {}
+
+ /// Constructs a string reference object from a C string and a size.
+ constexpr basic_string_view(const Char* s, size_t count) noexcept
+ : data_(s), size_(count) {}
+
+ constexpr basic_string_view(std::nullptr_t) = delete;
+
+ /// Constructs a string reference object from a C string.
+ FMT_CONSTEXPR20
+ basic_string_view(const Char* s)
+ : data_(s),
+ size_(detail::const_check(std::is_same::value &&
+ !detail::is_constant_evaluated(false))
+ ? strlen(reinterpret_cast(s))
+ : detail::length(s)) {}
+
+ /// Constructs a string reference from a `std::basic_string` or a
+ /// `std::basic_string_view` object.
+ template ::value&& std::is_same<
+ typename S::value_type, Char>::value)>
+ FMT_CONSTEXPR basic_string_view(const S& s) noexcept
+ : data_(s.data()), size_(s.size()) {}
+
+ /// Returns a pointer to the string data.
+ constexpr auto data() const noexcept -> const Char* { return data_; }
+
+ /// Returns the string size.
+ constexpr auto size() const noexcept -> size_t { return size_; }
+
+ constexpr auto begin() const noexcept -> iterator { return data_; }
+ constexpr auto end() const noexcept -> iterator { return data_ + size_; }
+
+ constexpr auto operator[](size_t pos) const noexcept -> const Char& {
+ return data_[pos];
+ }
+
+ FMT_CONSTEXPR void remove_prefix(size_t n) noexcept {
+ data_ += n;
+ size_ -= n;
+ }
+
+ FMT_CONSTEXPR auto starts_with(basic_string_view sv) const noexcept
+ -> bool {
+ return size_ >= sv.size_ && detail::compare(data_, sv.data_, sv.size_) == 0;
+ }
+ FMT_CONSTEXPR auto starts_with(Char c) const noexcept -> bool {
+ return size_ >= 1 && *data_ == c;
+ }
+ FMT_CONSTEXPR auto starts_with(const Char* s) const -> bool {
+ return starts_with(basic_string_view(s));
+ }
+
+ // Lexicographically compare this string reference to other.
+ FMT_CONSTEXPR auto compare(basic_string_view other) const -> int {
+ size_t str_size = size_ < other.size_ ? size_ : other.size_;
+ int result = detail::compare(data_, other.data_, str_size);
+ if (result == 0)
+ result = size_ == other.size_ ? 0 : (size_ < other.size_ ? -1 : 1);
+ return result;
+ }
+
+ FMT_CONSTEXPR friend auto operator==(basic_string_view lhs,
+ basic_string_view rhs) -> bool {
+ return lhs.compare(rhs) == 0;
+ }
+ friend auto operator!=(basic_string_view lhs, basic_string_view rhs) -> bool {
+ return lhs.compare(rhs) != 0;
+ }
+ friend auto operator<(basic_string_view lhs, basic_string_view rhs) -> bool {
+ return lhs.compare(rhs) < 0;
+ }
+ friend auto operator<=(basic_string_view lhs, basic_string_view rhs) -> bool {
+ return lhs.compare(rhs) <= 0;
+ }
+ friend auto operator>(basic_string_view lhs, basic_string_view rhs) -> bool {
+ return lhs.compare(rhs) > 0;
+ }
+ friend auto operator>=(basic_string_view lhs, basic_string_view rhs) -> bool {
+ return lhs.compare(rhs) >= 0;
+ }
+};
+
+FMT_EXPORT
+using string_view = basic_string_view;
+
+/// Specifies if `T` is a character type. Can be specialized by users.
+FMT_EXPORT
+template struct is_char : std::false_type {};
+template <> struct is_char : std::true_type {};
+
+namespace detail {
+
+// Constructs fmt::basic_string_view from types implicitly convertible
+// to it, deducing Char. Explicitly convertible types such as the ones returned
+// from FMT_STRING are intentionally excluded.
+template ::value)>
+constexpr auto to_string_view(const Char* s) -> basic_string_view {
+ return s;
+}
+template ::value)>
+constexpr auto to_string_view(const T& s)
+ -> basic_string_view {
+ return s;
+}
+template
+constexpr auto to_string_view(basic_string_view s)
+ -> basic_string_view {
+ return s;
+}
+
+template
+struct has_to_string_view : std::false_type {};
+// detail:: is intentional since to_string_view is not an extension point.
+template
+struct has_to_string_view<
+ T, void_t()))>>
+ : std::true_type {};
+
+template struct string_literal {
+ static constexpr Char value[sizeof...(C)] = {C...};
+ constexpr operator basic_string_view() const {
+ return {value, sizeof...(C)};
+ }
+};
+#if FMT_CPLUSPLUS < 201703L
+template
+constexpr Char string_literal::value[sizeof...(C)];
+#endif
+
+enum class type {
+ none_type,
+ // Integer types should go first,
+ int_type,
+ uint_type,
+ long_long_type,
+ ulong_long_type,
+ int128_type,
+ uint128_type,
+ bool_type,
+ char_type,
+ last_integer_type = char_type,
+ // followed by floating-point types.
+ float_type,
+ double_type,
+ long_double_type,
+ last_numeric_type = long_double_type,
+ cstring_type,
+ string_type,
+ pointer_type,
+ custom_type
+};
+
+// Maps core type T to the corresponding type enum constant.
+template
+struct type_constant : std::integral_constant {};
+
+#define FMT_TYPE_CONSTANT(Type, constant) \
+ template \
+ struct type_constant \
+ : std::integral_constant {}
+
+FMT_TYPE_CONSTANT(int, int_type);
+FMT_TYPE_CONSTANT(unsigned, uint_type);
+FMT_TYPE_CONSTANT(long long, long_long_type);
+FMT_TYPE_CONSTANT(unsigned long long, ulong_long_type);
+FMT_TYPE_CONSTANT(int128_opt, int128_type);
+FMT_TYPE_CONSTANT(uint128_opt, uint128_type);
+FMT_TYPE_CONSTANT(bool, bool_type);
+FMT_TYPE_CONSTANT(Char, char_type);
+FMT_TYPE_CONSTANT(float, float_type);
+FMT_TYPE_CONSTANT(double, double_type);
+FMT_TYPE_CONSTANT(long double, long_double_type);
+FMT_TYPE_CONSTANT(const Char*, cstring_type);
+FMT_TYPE_CONSTANT(basic_string_view, string_type);
+FMT_TYPE_CONSTANT(const void*, pointer_type);
+
+constexpr auto is_integral_type(type t) -> bool {
+ return t > type::none_type && t <= type::last_integer_type;
+}
+constexpr auto is_arithmetic_type(type t) -> bool {
+ return t > type::none_type && t <= type::last_numeric_type;
+}
+
+constexpr auto set(type rhs) -> int { return 1 << static_cast(rhs); }
+constexpr auto in(type t, int set) -> bool {
+ return ((set >> static_cast(t)) & 1) != 0;
+}
+
+// Bitsets of types.
+enum {
+ sint_set =
+ set(type::int_type) | set(type::long_long_type) | set(type::int128_type),
+ uint_set = set(type::uint_type) | set(type::ulong_long_type) |
+ set(type::uint128_type),
+ bool_set = set(type::bool_type),
+ char_set = set(type::char_type),
+ float_set = set(type::float_type) | set(type::double_type) |
+ set(type::long_double_type),
+ string_set = set(type::string_type),
+ cstring_set = set(type::cstring_type),
+ pointer_set = set(type::pointer_type)
+};
+} // namespace detail
+
+/// Reports a format error at compile time or, via a `format_error` exception,
+/// at runtime.
+// This function is intentionally not constexpr to give a compile-time error.
+FMT_NORETURN FMT_API void report_error(const char* message);
+
+FMT_DEPRECATED FMT_NORETURN inline void throw_format_error(
+ const char* message) {
+ report_error(message);
+}
+
+/// String's character (code unit) type.
+template ()))>
+using char_t = typename V::value_type;
+
+/**
+ * Parsing context consisting of a format string range being parsed and an
+ * argument counter for automatic indexing.
+ * You can use the `format_parse_context` type alias for `char` instead.
+ */
+FMT_EXPORT
+template class basic_format_parse_context {
+ private:
+ basic_string_view format_str_;
+ int next_arg_id_;
+
+ FMT_CONSTEXPR void do_check_arg_id(int id);
+
+ public:
+ using char_type = Char;
+ using iterator = const Char*;
+
+ explicit constexpr basic_format_parse_context(
+ basic_string_view format_str, int next_arg_id = 0)
+ : format_str_(format_str), next_arg_id_(next_arg_id) {}
+
+ /// Returns an iterator to the beginning of the format string range being
+ /// parsed.
+ constexpr auto begin() const noexcept -> iterator {
+ return format_str_.begin();
+ }
+
+ /// Returns an iterator past the end of the format string range being parsed.
+ constexpr auto end() const noexcept -> iterator { return format_str_.end(); }
+
+ /// Advances the begin iterator to `it`.
+ FMT_CONSTEXPR void advance_to(iterator it) {
+ format_str_.remove_prefix(detail::to_unsigned(it - begin()));
+ }
+
+ /// Reports an error if using the manual argument indexing; otherwise returns
+ /// the next argument index and switches to the automatic indexing.
+ FMT_CONSTEXPR auto next_arg_id() -> int {
+ if (next_arg_id_ < 0) {
+ report_error("cannot switch from manual to automatic argument indexing");
+ return 0;
+ }
+ int id = next_arg_id_++;
+ do_check_arg_id(id);
+ return id;
+ }
+
+ /// Reports an error if using the automatic argument indexing; otherwise
+ /// switches to the manual indexing.
+ FMT_CONSTEXPR void check_arg_id(int id) {
+ if (next_arg_id_ > 0) {
+ report_error("cannot switch from automatic to manual argument indexing");
+ return;
+ }
+ next_arg_id_ = -1;
+ do_check_arg_id(id);
+ }
+ FMT_CONSTEXPR void check_arg_id(basic_string_view) {
+ next_arg_id_ = -1;
+ }
+ FMT_CONSTEXPR void check_dynamic_spec(int arg_id);
+};
+
+FMT_EXPORT
+using format_parse_context = basic_format_parse_context;
+
+namespace detail {
+// A parse context with extra data used only in compile-time checks.
+template
+class compile_parse_context : public basic_format_parse_context {
+ private:
+ int num_args_;
+ const type* types_;
+ using base = basic_format_parse_context;
+
+ public:
+ explicit FMT_CONSTEXPR compile_parse_context(
+ basic_string_view format_str, int num_args, const type* types,
+ int next_arg_id = 0)
+ : base(format_str, next_arg_id), num_args_(num_args), types_(types) {}
+
+ constexpr auto num_args() const -> int { return num_args_; }
+ constexpr auto arg_type(int id) const -> type { return types_[id]; }
+
+ FMT_CONSTEXPR auto next_arg_id() -> int {
+ int id = base::next_arg_id();
+ if (id >= num_args_) report_error("argument not found");
+ return id;
+ }
+
+ FMT_CONSTEXPR void check_arg_id(int id) {
+ base::check_arg_id(id);
+ if (id >= num_args_) report_error("argument not found");
+ }
+ using base::check_arg_id;
+
+ FMT_CONSTEXPR void check_dynamic_spec(int arg_id) {
+ detail::ignore_unused(arg_id);
+ if (arg_id < num_args_ && types_ && !is_integral_type(types_[arg_id]))
+ report_error("width/precision is not integer");
+ }
+};
+
+/// A contiguous memory buffer with an optional growing ability. It is an
+/// internal class and shouldn't be used directly, only via `memory_buffer`.
+template class buffer {
+ private:
+ T* ptr_;
+ size_t size_;
+ size_t capacity_;
+
+ using grow_fun = void (*)(buffer& buf, size_t capacity);
+ grow_fun grow_;
+
+ protected:
+ // Don't initialize ptr_ since it is not accessed to save a few cycles.
+ FMT_MSC_WARNING(suppress : 26495)
+ FMT_CONSTEXPR20 buffer(grow_fun grow, size_t sz) noexcept
+ : size_(sz), capacity_(sz), grow_(grow) {}
+
+ constexpr buffer(grow_fun grow, T* p = nullptr, size_t sz = 0,
+ size_t cap = 0) noexcept
+ : ptr_(p), size_(sz), capacity_(cap), grow_(grow) {}
+
+ FMT_CONSTEXPR20 ~buffer() = default;
+ buffer(buffer&&) = default;
+
+ /// Sets the buffer data and capacity.
+ FMT_CONSTEXPR void set(T* buf_data, size_t buf_capacity) noexcept {
+ ptr_ = buf_data;
+ capacity_ = buf_capacity;
+ }
+
+ public:
+ using value_type = T;
+ using const_reference = const T&;
+
+ buffer(const buffer&) = delete;
+ void operator=(const buffer&) = delete;
+
+ auto begin() noexcept -> T* { return ptr_; }
+ auto end() noexcept -> T* { return ptr_ + size_; }
+
+ auto begin() const noexcept -> const T* { return ptr_; }
+ auto end() const noexcept -> const T* { return ptr_ + size_; }
+
+ /// Returns the size of this buffer.
+ constexpr auto size() const noexcept -> size_t { return size_; }
+
+ /// Returns the capacity of this buffer.
+ constexpr auto capacity() const noexcept -> size_t { return capacity_; }
+
+ /// Returns a pointer to the buffer data (not null-terminated).
+ FMT_CONSTEXPR auto data() noexcept -> T* { return ptr_; }
+ FMT_CONSTEXPR auto data() const noexcept -> const T* { return ptr_; }
+
+ /// Clears this buffer.
+ void clear() { size_ = 0; }
+
+ // Tries resizing the buffer to contain `count` elements. If T is a POD type
+ // the new elements may not be initialized.
+ FMT_CONSTEXPR void try_resize(size_t count) {
+ try_reserve(count);
+ size_ = count <= capacity_ ? count : capacity_;
+ }
+
+ // Tries increasing the buffer capacity to `new_capacity`. It can increase the
+ // capacity by a smaller amount than requested but guarantees there is space
+ // for at least one additional element either by increasing the capacity or by
+ // flushing the buffer if it is full.
+ FMT_CONSTEXPR void try_reserve(size_t new_capacity) {
+ if (new_capacity > capacity_) grow_(*this, new_capacity);
+ }
+
+ FMT_CONSTEXPR void push_back(const T& value) {
+ try_reserve(size_ + 1);
+ ptr_[size_++] = value;
+ }
+
+ /// Appends data to the end of the buffer.
+ template void append(const U* begin, const U* end) {
+ while (begin != end) {
+ auto count = to_unsigned(end - begin);
+ try_reserve(size_ + count);
+ auto free_cap = capacity_ - size_;
+ if (free_cap < count) count = free_cap;
+ // A loop is faster than memcpy on small sizes.
+ T* out = ptr_ + size_;
+ for (size_t i = 0; i < count; ++i) out[i] = begin[i];
+ size_ += count;
+ begin += count;
+ }
+ }
+
+ template FMT_CONSTEXPR auto operator[](Idx index) -> T& {
+ return ptr_[index];
+ }
+ template
+ FMT_CONSTEXPR auto operator[](Idx index) const -> const T& {
+ return ptr_[index];
+ }
+};
+
+struct buffer_traits {
+ explicit buffer_traits(size_t) {}
+ auto count() const -> size_t { return 0; }
+ auto limit(size_t size) -> size_t { return size; }
+};
+
+class fixed_buffer_traits {
+ private:
+ size_t count_ = 0;
+ size_t limit_;
+
+ public:
+ explicit fixed_buffer_traits(size_t limit) : limit_(limit) {}
+ auto count() const -> size_t { return count_; }
+ auto limit(size_t size) -> size_t {
+ size_t n = limit_ > count_ ? limit_ - count_ : 0;
+ count_ += size;
+ return size < n ? size : n;
+ }
+};
+
+// A buffer that writes to an output iterator when flushed.
+template
+class iterator_buffer : public Traits, public buffer {
+ private:
+ OutputIt out_;
+ enum { buffer_size = 256 };
+ T data_[buffer_size];
+
+ static FMT_CONSTEXPR void grow(buffer& buf, size_t) {
+ if (buf.size() == buffer_size) static_cast(buf).flush();
+ }
+
+ void flush() {
+ auto size = this->size();
+ this->clear();
+ const T* begin = data_;
+ const T* end = begin + this->limit(size);
+ while (begin != end) *out_++ = *begin++;
+ }
+
+ public:
+ explicit iterator_buffer(OutputIt out, size_t n = buffer_size)
+ : Traits(n), buffer(grow, data_, 0, buffer_size), out_(out) {}
+ iterator_buffer(iterator_buffer&& other) noexcept
+ : Traits(other),
+ buffer(grow, data_, 0, buffer_size),
+ out_(other.out_) {}
+ ~iterator_buffer() {
+ // Don't crash if flush fails during unwinding.
+ FMT_TRY { flush(); }
+ FMT_CATCH(...) {}
+ }
+
+ auto out() -> OutputIt {
+ flush();
+ return out_;
+ }
+ auto count() const -> size_t { return Traits::count() + this->size(); }
+};
+
+template
+class iterator_buffer : public fixed_buffer_traits,
+ public buffer {
+ private:
+ T* out_;
+ enum { buffer_size = 256 };
+ T data_[buffer_size];
+
+ static FMT_CONSTEXPR void grow(buffer& buf, size_t) {
+ if (buf.size() == buf.capacity())
+ static_cast(buf).flush();
+ }
+
+ void flush() {
+ size_t n = this->limit(this->size());
+ if (this->data() == out_) {
+ out_ += n;
+ this->set(data_, buffer_size);
+ }
+ this->clear();
+ }
+
+ public:
+ explicit iterator_buffer(T* out, size_t n = buffer_size)
+ : fixed_buffer_traits(n), buffer(grow, out, 0, n), out_(out) {}
+ iterator_buffer(iterator_buffer&& other) noexcept
+ : fixed_buffer_traits(other),
+ buffer(static_cast(other)),
+ out_(other.out_) {
+ if (this->data() != out_) {
+ this->set(data_, buffer_size);
+ this->clear();
+ }
+ }
+ ~iterator_buffer() { flush(); }
+
+ auto out() -> T* {
+ flush();
+ return out_;
+ }
+ auto count() const -> size_t {
+ return fixed_buffer_traits::count() + this->size();
+ }
+};
+
+template class iterator_buffer : public buffer {
+ public:
+ explicit iterator_buffer(T* out, size_t = 0)
+ : buffer([](buffer&, size_t) {}, out, 0, ~size_t()) {}
+
+ auto out() -> T* { return &*this->end(); }
+};
+
+// A buffer that writes to a container with the contiguous storage.
+template
+class iterator_buffer<
+ OutputIt,
+ enable_if_t::value &&
+ is_contiguous::value,
+ typename OutputIt::container_type::value_type>>
+ : public buffer {
+ private:
+ using container_type = typename OutputIt::container_type;
+ using value_type = typename container_type::value_type;
+ container_type& container_;
+
+ static FMT_CONSTEXPR void grow(buffer& buf, size_t capacity) {
+ auto& self = static_cast(buf);
+ self.container_.resize(capacity);
+ self.set(&self.container_[0], capacity);
+ }
+
+ public:
+ explicit iterator_buffer(container_type& c)
+ : buffer(grow, c.size()), container_(c) {}
+ explicit iterator_buffer(OutputIt out, size_t = 0)
+ : iterator_buffer(get_container(out)) {}
+
+ auto out() -> OutputIt { return back_inserter(container_); }
+};
+
+// A buffer that counts the number of code units written discarding the output.
+template class counting_buffer : public buffer {
+ private:
+ enum { buffer_size = 256 };
+ T data_[buffer_size];
+ size_t count_ = 0;
+
+ static FMT_CONSTEXPR void grow(buffer& buf, size_t) {
+ if (buf.size() != buffer_size) return;
+ static_cast(buf).count_ += buf.size();
+ buf.clear();
+ }
+
+ public:
+ counting_buffer() : buffer(grow, data_, 0, buffer_size) {}
+
+ auto count() -> size_t { return count_ + this->size(); }
+};
+} // namespace detail
+
+template
+FMT_CONSTEXPR void basic_format_parse_context::do_check_arg_id(int id) {
+ // Argument id is only checked at compile-time during parsing because
+ // formatting has its own validation.
+ if (detail::is_constant_evaluated() &&
+ (!FMT_GCC_VERSION || FMT_GCC_VERSION >= 1200)) {
+ using context = detail::compile_parse_context;
+ if (id >= static_cast(this)->num_args())
+ report_error("argument not found");
+ }
+}
+
+template
+FMT_CONSTEXPR void basic_format_parse_context::check_dynamic_spec(
+ int arg_id) {
+ if (detail::is_constant_evaluated() &&
+ (!FMT_GCC_VERSION || FMT_GCC_VERSION >= 1200)) {
+ using context = detail::compile_parse_context;
+ static_cast(this)->check_dynamic_spec(arg_id);
+ }
+}
+
+FMT_EXPORT template class basic_format_arg;
+FMT_EXPORT template class basic_format_args;
+FMT_EXPORT template class dynamic_format_arg_store;
+
+// A formatter for objects of type T.
+FMT_EXPORT
+template
+struct formatter {
+ // A deleted default constructor indicates a disabled formatter.
+ formatter() = delete;
+};
+
+// Specifies if T has an enabled formatter specialization. A type can be
+// formattable even if it doesn't have a formatter e.g. via a conversion.
+template
+using has_formatter =
+ std::is_constructible>;
+
+// An output iterator that appends to a buffer. It is used instead of
+// back_insert_iterator to reduce symbol sizes and avoid dependency.
+template class basic_appender {
+ private:
+ detail::buffer