import { assert } from "../../assert.js";

/**
 *
 * @param {string} text
 * @param {number} cursor
 * @param {number} limit
 * @returns {number}
 */
export function skipWhitespace(text, cursor, limit) {
    assert.isString(text, 'text');
    assert.isNonNegativeInteger(cursor, 'cursor');
    assert.isNonNegativeInteger(limit, 'limit');

    let i = cursor;
    let char;

    while (i < limit) {
        char = text.charAt(i);

        if (char === ' ' || char === '\n' || char === '\t') {
            i++;
        } else {
            break;
        }
    }

    return i;
}
