"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isResourceId = exports.extractPlaceholderTokens = exports.strTrim = exports.strIsNullOrEmpty = exports.STR_EMPTY = exports.strReplaceAll = exports.strStartsWith = exports.strEndsWith = void 0;
/**
 * Indicates if the given string ends with the given suffix
 *
 * @export
 * @param {string} str
 * @param {string} suffix
 * @returns {boolean}
 */
function strEndsWith(str, suffix) {
    return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
exports.strEndsWith = strEndsWith;
/**
 * Indicates if the given string starts with the given string
 *
 * @param {string} str
 * @param {string} word
 * @returns {boolean}
 * @since 0.14
 */
function strStartsWith(str, word) {
    return str.lastIndexOf(word, 0) === 0;
}
exports.strStartsWith = strStartsWith;
/**
 * Replaces all occurrences of the given string with the specified replacement in the target
 * string
 *
 * @param str
 * @param find
 * @param replace
 * @since 0.12
 */
function strReplaceAll(str, find, replace) {
    return str.split(find).join(replace);
}
exports.strReplaceAll = strReplaceAll;
/**
 * Empty string constant
 */
exports.STR_EMPTY = "";
/**
 * Indicates if the given string is null or empty
 *
 * @export
 * @param {(string | null | undefined)} str
 * @returns {boolean}
 */
function strIsNullOrEmpty(str) {
    return null == str || "" === str;
}
exports.strIsNullOrEmpty = strIsNullOrEmpty;
/**
 * Returns a trimmed version of the given string
 *
 * @param str The string to trim
 * @since 0.12.5
 */
function strTrim(str) {
    if (!String.prototype.trim) {
        return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
    }
    return str.trim();
}
exports.strTrim = strTrim;
/**
 *
 *
 * @export
 * @param {string} expr
 * @param {string} delimBegin
 * @param {string} delimEnd
 * @returns
 * @since 0.14
 */
function extractPlaceholderTokens(expr, delimBegin, delimEnd) {
    var _a;
    var regex = new RegExp("".concat(delimBegin, "(.*?)").concat(delimEnd), "g");
    var matches = expr.match(regex);
    return (_a = matches === null || matches === void 0 ? void 0 : matches.map(function (m) { return m.replace(delimBegin, "").replace(delimEnd, ""); })) !== null && _a !== void 0 ? _a : [];
}
exports.extractPlaceholderTokens = extractPlaceholderTokens;
/**
 * Gets whether the given string is a resource identifier
 *
 * @param str The string to test
 * @since 0.14
 */
function isResourceId(str) {
    return strStartsWith(str, "Library://");
}
exports.isResourceId = isResourceId;
//# sourceMappingURL=string.js.map