Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,69 +62,70 @@ var emojiProperty = grapheme.emojiProperty;
* var out = prevGraphemeClusterBreak( '🌷', 1 );
* // returns -1
*/
// cspell:ignore अनुच्छेद
function prevGraphemeClusterBreak( str, fromIndex ) {
var breaks;
var emoji;
var ans;
var len;
var idx;
var cp;
var i;

if ( !isString( str ) ) {
throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );
}
len = str.length;
if ( arguments.length > 1 ) {
if ( !isInteger( fromIndex ) ) {
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) );
}
idx = fromIndex;
} else {
idx = len - 1;
}
if ( len === 0 || idx <= 0 ) {
return -1;
}
if ( idx >= len ) {
idx = len - 1;
}

// Initialize caches for storing grapheme break and emoji properties:
breaks = [];
emoji = [];

// Get the code point for the starting index:
cp = codePointAt( str, 0 );

// Get the corresponding grapheme break and emoji properties:
breaks.push( breakProperty( cp ) );
emoji.push( emojiProperty( cp ) );

ans = -1;
for ( i = 1; i <= idx; i++ ) {
// If the current character is part of a surrogate pair, move along...
if ( hasUTF16SurrogatePairAt( str, i-1 ) ) {
ans = i-2;
breaks.length = 0;
emoji.length = 0;
continue;
}
cp = codePointAt( str, i );

// Get the corresponding grapheme break and emoji properties:
breaks.push( breakProperty( cp ) );
emoji.push( emojiProperty( cp ) );

// Determine if we've encountered a grapheme cluster break...
if ( breakType( breaks, emoji ) > 0 ) {
ans = i-1;
breaks.length = 0;
emoji.length = 0;
continue;
}
}
return ans;
var breaks;
var emoji;
var ans;
var len;
var idx;
var cp;
var i;

if ( !isString( str ) ) {
throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) );
}
len = str.length;
if ( arguments.length > 1 ) {
if ( !isInteger( fromIndex ) ) {
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) );
}
idx = fromIndex;
} else {
idx = len - 1;
}
if ( len === 0 || idx <= 0 ) {
return -1;
}
if ( idx >= len ) {
idx = len - 1;
}

// Initialize caches for storing grapheme break and emoji properties:
breaks = [];
emoji = [];

// Get the code point for the starting index:
cp = codePointAt( str, 0 );

// Get the corresponding grapheme break and emoji properties:
breaks.push( breakProperty( cp ) );
emoji.push( emojiProperty( cp ) );

ans = -1;
for ( i = 1; i <= idx; i++ ) {
// If the current character is part of a surrogate pair, move along...
if ( hasUTF16SurrogatePairAt( str, i-1 ) ) {
ans = i-2;
breaks.length = 0;
emoji.length = 0;
continue;
}
cp = codePointAt( str, i );

// Get the corresponding grapheme break and emoji properties:
breaks.push( breakProperty( cp ) );
emoji.push( emojiProperty( cp ) );

// Determine if we've encountered a grapheme cluster break...
if ( breakType( breaks, emoji ) > 0 ) {
ans = i-1;
breaks.length = 0;
emoji.length = 0;
continue;
}
}
return ans;
}


Expand Down
Loading