From 203113f227028defc399917968cb478a2e28ba18 Mon Sep 17 00:00:00 2001 From: Bastian Huber Date: Mon, 19 Aug 2024 09:27:25 +0000 Subject: [PATCH 1/2] Added support for original field and type naming for C++ language. --- .../src/language/CPlusPlus/language.ts | 4 ++++ packages/quicktype-core/src/support/Strings.ts | 14 +++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/quicktype-core/src/language/CPlusPlus/language.ts b/packages/quicktype-core/src/language/CPlusPlus/language.ts index 292d21a114..36026f8525 100644 --- a/packages/quicktype-core/src/language/CPlusPlus/language.ts +++ b/packages/quicktype-core/src/language/CPlusPlus/language.ts @@ -7,6 +7,7 @@ import { type FixMeOptionsAnyType, type FixMeOptionsType } from "../../types"; import { CPlusPlusRenderer } from "./CPlusPlusRenderer"; const pascalValue: [string, NamingStyle] = ["pascal-case", "pascal"]; +const originalValue: [string, NamingStyle] = ["original-case", "original"]; const underscoreValue: [string, NamingStyle] = ["underscore-case", "underscore"]; const camelValue: [string, NamingStyle] = ["camel-case", "camel"]; const upperUnderscoreValue: [string, NamingStyle] = ["upper-underscore-case", "upper-underscore"]; @@ -66,6 +67,7 @@ export const cPlusPlusOptions = { enumType: new StringOption("enum-type", "Type of enum class", "NAME", "int", "secondary"), typeNamingStyle: new EnumOption("type-style", "Naming style for types", [ pascalValue, + originalValue, underscoreValue, camelValue, upperUnderscoreValue, @@ -75,6 +77,7 @@ export const cPlusPlusOptions = { memberNamingStyle: new EnumOption("member-style", "Naming style for members", [ underscoreValue, pascalValue, + originalValue, camelValue, upperUnderscoreValue, pascalUpperAcronymsValue, @@ -84,6 +87,7 @@ export const cPlusPlusOptions = { upperUnderscoreValue, underscoreValue, pascalValue, + originalValue, camelValue, pascalUpperAcronymsValue, camelUpperAcronymsValue diff --git a/packages/quicktype-core/src/support/Strings.ts b/packages/quicktype-core/src/support/Strings.ts index 1b0614ad5e..ca6a550a7d 100644 --- a/packages/quicktype-core/src/support/Strings.ts +++ b/packages/quicktype-core/src/support/Strings.ts @@ -11,7 +11,8 @@ export type NamingStyle = | "underscore" | "upper-underscore" | "pascal-upper-acronyms" - | "camel-upper-acronyms"; + | "camel-upper-acronyms" + | "original"; function computeAsciiMap(mapper: (codePoint: number) => string): { charNoEscapeMap: number[]; @@ -419,7 +420,7 @@ export function splitIntoWords(s: string): WordInName[] { return i - intervalStart; } - for (;;) { + for (; ;) { skipNonWord(); if (atEnd()) break; @@ -561,7 +562,8 @@ export function makeNameStyle( namingStyle === "pascal" || namingStyle === "camel" || namingStyle === "pascal-upper-acronyms" || - namingStyle === "camel-upper-acronyms" + namingStyle === "camel-upper-acronyms" || + namingStyle === "original" ) { separator = ""; if (namingStyle === "pascal-upper-acronyms" || namingStyle === "camel-upper-acronyms") { @@ -589,11 +591,17 @@ export function makeNameStyle( case "upper-underscore": firstWordStyle = restWordStyle = firstWordAcronymStyle = restAcronymStyle = allUpperWordStyle; break; + case "original": + firstWordStyle = restWordStyle = firstWordAcronymStyle = restAcronymStyle = originalWord; + break; default: return assertNever(namingStyle); } return (original: string) => { + if (namingStyle === "original") + return original; + const words = splitIntoWords(original); const styledName = combineWords( From 0e0bc1b3b3144ffa71d5d8b02ab01a1b63c35f11 Mon Sep 17 00:00:00 2001 From: Mark Probst Date: Sun, 12 Jul 2026 16:29:33 -0400 Subject: [PATCH 2/2] Legalize identifiers in the "original" naming style The "original" style returned names verbatim, skipping combineWords entirely, so JSON keys that aren't valid identifiers produced uncompilable C++ (e.g. "some-header" emitted as a member name, or a leading-digit key like "9lives"). Route "original" through combineWords as a single unsplit word instead: casing and legal characters (including underscores) are preserved exactly, while illegal characters are stripped, invalid start characters get the usual "the" prefix, and empty names are handled. This matches the semantics of the existing "--acronym-style original" option. Reserved words like "class" were already handled by the renderer's forbidden-names machinery and still are. Co-Authored-By: Claude Fable 5 --- packages/quicktype-core/src/support/Strings.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/quicktype-core/src/support/Strings.ts b/packages/quicktype-core/src/support/Strings.ts index 5fcfb0c392..3470989254 100644 --- a/packages/quicktype-core/src/support/Strings.ts +++ b/packages/quicktype-core/src/support/Strings.ts @@ -647,10 +647,13 @@ export function makeNameStyle( } return (original: string) => { - if (namingStyle === "original") - return original; - - const words = splitIntoWords(original); + // "original" must not split or restyle the name, but it still has + // to go through combineWords so that illegal characters, empty + // names, and invalid start characters are fixed up. + const words: WordInName[] = + namingStyle === "original" + ? [{ word: original, isAcronym: false }] + : splitIntoWords(original); const styledName = combineWords( words,