MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / GenerateCppFile

Method GenerateCppFile

localization/GenerateCpp.cs:7–25  ·  view source on GitHub ↗
(string languageName, Dictionary<string, string> dictionary)

Source from the content-addressed store, hash-verified

5
6public class LocalizationGenerator {
7 public static string GenerateCppFile(string languageName, Dictionary<string, string> dictionary) {
8 var sb = new StringBuilder();
9
10 sb.AppendLine("#include <utility>");
11 sb.AppendLine("#include <array>");
12 sb.AppendLine();
13
14 // Используем std::array для поддержки std::span в будущем
15 sb.AppendLine($"constexpr std::array<std::pair<const char*, const char*>, {dictionary.Count}> _Localization_{languageName} = {{{{");
16
17 var entries = dictionary.Select(kv =>
18 $" {{\"{Escape(kv.Key)}\", \"{Escape(kv.Value)}\"}}"
19 );
20
21 sb.AppendLine(string.Join("," + Environment.NewLine, entries));
22 sb.AppendLine("}};");
23
24 return sb.ToString();
25 }
26
27 private static string Escape(string s) {
28 return s.Replace("\\", "\\\\").Replace("\"", "\\\"");

Callers 1

MainMethod · 0.80

Calls 1

ToStringMethod · 0.45

Tested by

no test coverage detected