Skip to content

Commit

Permalink
fix: update examples, fix tests and bug when a paired surrogate is at…
Browse files Browse the repository at this point in the history
… the end of the string
  • Loading branch information
steff456 committed Nov 10, 2023
1 parent 392881b commit 7857375
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
12 changes: 6 additions & 6 deletions lib/node_modules/@stdlib/string/next-code-point-index/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ var out = nextCodePointIndex( 'last man standing', 4 );
out = nextCodePointIndex( 'presidential election', 8 );
// returns 9

out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 1 );
// returns 3
out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 0 );
// returns 2

out = nextCodePointIndex( '🌷', 0 );
// returns -1
Expand Down Expand Up @@ -145,15 +145,15 @@ Options:
### Examples

```bash
$ next-code-point-index --from=1 𐒻𐓟𐒻𐓟
3
$ next-code-point-index --from=0 𐒻𐓟𐒻𐓟
2
```

To use as a [standard stream][standard-streams],

```bash
$ echo -n '𐒻𐓟𐒻𐓟' | next-code-point-index --from=1
3
$ echo -n '𐒻𐓟𐒻𐓟' | next-code-point-index --from=0
2
```

</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
5
> out = {{alias}}( 'presidential election', 8 )
9
> out = {{alias}}( '𐒻𐓟𐒻𐓟', 1 )
3
> out = {{alias}}( '𐒻𐓟𐒻𐓟', 0 )
2
> out = {{alias}}( '🌷' )
-1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
* @returns next code point position
*
* @example
* var out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 1 );
* // returns 3
* var out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 0 );
* // returns 2
*
* out = nextCodePointIndex( '🌷' );
* // returns -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ console.log( nextCodePointIndex( 'last man standing', 4 ) );
console.log( nextCodePointIndex( 'presidential election', 8 ) );
// => 9

console.log( nextCodePointIndex( '𐒻𐓟𐒻𐓟', 1 ) );
// => 3
console.log( nextCodePointIndex( '𐒻𐓟𐒻𐓟', 0 ) );
// => 2

console.log( nextCodePointIndex( '🌷', 0 ) );
// => -1
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
* @example
* var nextCodePointIndex = require( '@stdlib/string/next-code-point-index' );
*
* var out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 1 );
* // returns 3
* var out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 0 );
* // returns 2
*
* out = nextCodePointIndex( '🌷', 0 );
* // returns -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var RE_UTF16_HIGH_SURROGATE = /[\uD800-\uDBFF]/; // TODO: replace with stdlib pk
* @param {integer} [fromIndex=0] - position
* @throws {TypeError} first argument must be a string
* @throws {TypeError} second argument must be an integer
* @returns {Integer} position of the next Unicode code point
* @returns {integer} position of the next Unicode code point
*
* @example
* var out = nextCodePointIndex( 'last man standing', 4 );
Expand All @@ -51,8 +51,8 @@ var RE_UTF16_HIGH_SURROGATE = /[\uD800-\uDBFF]/; // TODO: replace with stdlib pk
* // returns 9
*
* @example
* var out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 1 );
* // returns 3
* var out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 0 );
* // returns 2
*
* @example
* var out = nextCodePointIndex( '🌷' );
Expand Down Expand Up @@ -95,7 +95,7 @@ function nextCodePointIndex( str, fromIndex ) {
// Check whether the high surrogate is paired with a low surrogate...
if ( RE_UTF16_LOW_SURROGATE.test( str[ i ] ) ) {
// We found a surrogate pair:
return ( j === lastIndex ) ? -1 : j;
return ( j >= lastIndex ) ? -1 : j;
}
return i;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ tape( 'the function supports providing an index from which to begin searching',
out = nextCodePointIndex( 'अनुच्छेद', 1 );
t.strictEqual( out, 2, 'returns expected value' );

out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 1 );
t.strictEqual( out, 3, 'returns expected value' );
out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 0 );
t.strictEqual( out, 2, 'returns expected value' );

out = nextCodePointIndex( 'a\uDBFFaaaaaaa', 0 ); // unpaired high surrogate
t.strictEqual( out, 1, 'returns expected value' );
Expand Down

0 comments on commit 7857375

Please sign in to comment.