Skip to content

Commit

Permalink
Recognize half width characters
Browse files Browse the repository at this point in the history
  • Loading branch information
as-cii committed Oct 15, 2015
1 parent abf3069 commit 1fc9a25
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions spec/text-utils-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,10 @@ describe 'text utilities', ->
expect(textUtils.isDoubleWidthCharacter("")).toBe(true)

expect(textUtils.isDoubleWidthCharacter("a")).toBe(false)

describe ".isHalfWidthCharacter(character)", ->
it "returns true when the character is an half width form", ->
expect(textUtils.isHalfWidthCharacter("")).toBe(true)
expect(textUtils.isHalfWidthCharacter("")).toBe(true)
expect(textUtils.isHalfWidthCharacter("")).toBe(true)
expect(textUtils.isHalfWidthCharacter("B")).toBe(false)
7 changes: 6 additions & 1 deletion src/text-utils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ isDoubleWidthCharacter = (character) ->
isCjkUnifiedIdeograph(charCode) or
isFullWidthForm(charCode)

isHalfWidthCharacter = (character) ->
charCode = character.charCodeAt(0)

0xFF65 <= charCode <= 0xFFDC

# Does the given string contain at least surrogate pair, variation sequence,
# or combined character?
#
Expand All @@ -94,4 +99,4 @@ hasPairedCharacter = (string) ->
index++
false

module.exports = {isPairedCharacter, hasPairedCharacter, isDoubleWidthCharacter}
module.exports = {isPairedCharacter, hasPairedCharacter, isDoubleWidthCharacter, isHalfWidthCharacter}

0 comments on commit 1fc9a25

Please sign in to comment.