[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for original field and type naming for C++ language. #2639

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/quicktype-core/src/language/CPlusPlus/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down Expand Up @@ -66,6 +67,7 @@ export const cPlusPlusOptions = {
enumType: new StringOption("enum-type", "Type of enum class", "NAME", "int", "secondary"),
typeNamingStyle: new EnumOption<NamingStyle>("type-style", "Naming style for types", [
pascalValue,
originalValue,
underscoreValue,
camelValue,
upperUnderscoreValue,
Expand All @@ -75,6 +77,7 @@ export const cPlusPlusOptions = {
memberNamingStyle: new EnumOption<NamingStyle>("member-style", "Naming style for members", [
underscoreValue,
pascalValue,
originalValue,
camelValue,
upperUnderscoreValue,
pascalUpperAcronymsValue,
Expand All @@ -84,6 +87,7 @@ export const cPlusPlusOptions = {
upperUnderscoreValue,
underscoreValue,
pascalValue,
originalValue,
camelValue,
pascalUpperAcronymsValue,
camelUpperAcronymsValue
Expand Down
14 changes: 11 additions & 3 deletions packages/quicktype-core/src/support/Strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -419,7 +420,7 @@ export function splitIntoWords(s: string): WordInName[] {
return i - intervalStart;
}

for (;;) {
for (; ;) {
skipNonWord();
if (atEnd()) break;

Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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(
Expand Down