"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringEscape = void 0;
exports.javaNameStyle = javaNameStyle;
const Strings_js_1 = require("../../support/Strings.js");
exports.stringEscape = (0, Strings_js_1.utf16ConcatMap)((0, Strings_js_1.escapeNonPrintableMapper)(Strings_js_1.isAscii, Strings_js_1.standardUnicodeHexEscape));
function isStartCharacter(codePoint) {
    if (codePoint === 0x5f)
        return true; // underscore
    return (0, Strings_js_1.isAscii)(codePoint) && (0, Strings_js_1.isLetter)(codePoint);
}
function isPartCharacter(codePoint) {
    return (isStartCharacter(codePoint) ||
        ((0, Strings_js_1.isAscii)(codePoint) && (0, Strings_js_1.isDigit)(codePoint)));
}
const legalizeName = (0, Strings_js_1.utf16LegalizeCharacters)(isPartCharacter);
function javaNameStyle(startWithUpper, upperUnderscore, original, acronymsStyle = Strings_js_1.allUpperWordStyle) {
    const words = (0, Strings_js_1.splitIntoWords)(original);
    return (0, Strings_js_1.combineWords)(words, legalizeName, upperUnderscore
        ? Strings_js_1.allUpperWordStyle
        : startWithUpper
            ? Strings_js_1.firstUpperWordStyle
            : Strings_js_1.allLowerWordStyle, upperUnderscore ? Strings_js_1.allUpperWordStyle : Strings_js_1.firstUpperWordStyle, upperUnderscore || startWithUpper
        ? Strings_js_1.allUpperWordStyle
        : Strings_js_1.allLowerWordStyle, 
    // For UPPER_UNDERSCORE style (Java enum constants), always use allUpperWordStyle for acronyms
    // to maintain consistency with the naming convention (e.g., XXX_SPA_XXX)
    upperUnderscore ? Strings_js_1.allUpperWordStyle : acronymsStyle, upperUnderscore ? "_" : "", isStartCharacter);
}
