import { allLowerWordStyle, allUpperWordStyle, combineWords, escapeNonPrintableMapper, firstUpperWordStyle, intToHex, isDigit, isLetterOrUnderscore, isNumeric, isPrintable, legalizeCharacters, splitIntoWords, utf32ConcatMap, } from "../../support/Strings.js";
function isPartCharacter(codePoint) {
    return isLetterOrUnderscore(codePoint) || isNumeric(codePoint);
}
function isStartCharacter(codePoint) {
    return isPartCharacter(codePoint) && !isDigit(codePoint);
}
const legalizeName = legalizeCharacters(isPartCharacter);
export function kotlinNameStyle(isUpper, original, acronymsStyle = allUpperWordStyle) {
    const words = splitIntoWords(original);
    return combineWords(words, legalizeName, isUpper ? firstUpperWordStyle : allLowerWordStyle, firstUpperWordStyle, isUpper ? allUpperWordStyle : allLowerWordStyle, acronymsStyle, "", isStartCharacter);
}
function unicodeEscape(codePoint) {
    return "\\u" + intToHex(codePoint, 4);
}
// eslint-disable-next-line @typescript-eslint/naming-convention
const _stringEscape = utf32ConcatMap(escapeNonPrintableMapper(isPrintable, unicodeEscape));
export function stringEscape(s) {
    // "$this" is a template string in Kotlin so we have to escape $
    return _stringEscape(s).replace(/\$/g, "\\$");
}
