import { funPrefixNamer } from "../../Naming.js";
import { allLowerWordStyle, combineWords, escapeNonPrintableMapper, firstUpperWordStyle, intToHex, isAscii, isLetterOrUnderscore, isLetterOrUnderscoreOrDigit, isPrintable, legalizeCharacters, splitIntoWords, utf32ConcatMap, } from "../../support/Strings.js";
function isAsciiLetterOrUnderscoreOrDigit(codePoint) {
    if (!isAscii(codePoint)) {
        return false;
    }
    return isLetterOrUnderscoreOrDigit(codePoint);
}
function isAsciiLetterOrUnderscore(codePoint) {
    if (!isAscii(codePoint)) {
        return false;
    }
    return isLetterOrUnderscore(codePoint);
}
const legalizeName = legalizeCharacters(isAsciiLetterOrUnderscoreOrDigit);
function crystalStyle(original, isSnakeCase) {
    const words = splitIntoWords(original);
    const wordStyle = isSnakeCase ? allLowerWordStyle : firstUpperWordStyle;
    const combined = combineWords(words, legalizeName, wordStyle, wordStyle, wordStyle, wordStyle, isSnakeCase ? "_" : "", isAsciiLetterOrUnderscore);
    return combined === "_" ? "_underscore" : combined;
}
export const snakeNamingFunction = funPrefixNamer("default", (original) => crystalStyle(original, true));
export const camelNamingFunction = funPrefixNamer("camel", (original) => crystalStyle(original, false));
function standardUnicodeCrystalEscape(codePoint) {
    if (codePoint <= 0xffff) {
        return "\\u{" + intToHex(codePoint, 4) + "}";
    }
    else {
        return "\\u{" + intToHex(codePoint, 6) + "}";
    }
}
export const crystalStringEscape = utf32ConcatMap(escapeNonPrintableMapper(isPrintable, standardUnicodeCrystalEscape));
