From f63866b2a2b8030d6767a9fb549da23833af13d5 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 4 Jun 2013 12:12:14 -0700 Subject: [PATCH] Rename hasSurrogatePairs() to hasSurrogatePair() --- spec/stdlib/text-utils-spec.coffee | 6 ++++++ src/app/token.coffee | 6 +++--- src/stdlib/text-utils.coffee | 7 +++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/spec/stdlib/text-utils-spec.coffee b/spec/stdlib/text-utils-spec.coffee index 5732fa09e..907c5b297 100644 --- a/spec/stdlib/text-utils-spec.coffee +++ b/spec/stdlib/text-utils-spec.coffee @@ -7,6 +7,12 @@ describe 'text utilities', -> expect(textUtils.getCharacterCount('a\uD835\uDF97b\uD835\uDF97c')).toBe 5 expect(textUtils.getCharacterCount('\uD835\uDF97')).toBe 1 + describe '.hasSurrogatePair(string)', -> + it 'returns true when the string contains a surrogate pair', -> + expect(textUtils.hasSurrogatePair('abc')).toBe false + expect(textUtils.hasSurrogatePair('a\uD835\uDF97b\uD835\uDF97c')).toBe true + expect(textUtils.hasSurrogatePair('\uD835\uDF97')).toBe true + describe '.isSurrogatePair(string, index)', -> it 'returns true when the index is the start of a high/low surrogate pair', -> expect(textUtils.isSurrogatePair('a\uD835\uDF97b\uD835\uDF97c', 0)).toBe false diff --git a/src/app/token.coffee b/src/app/token.coffee index b4cee6fd6..8fae0930f 100644 --- a/src/app/token.coffee +++ b/src/app/token.coffee @@ -4,7 +4,7 @@ textUtils = require 'text-utils' module.exports = class Token value: null - hasSurrogatePairs: false + hasSurrogatePair: false scopes: null isAtomic: null isHardTab: null @@ -14,7 +14,7 @@ class Token constructor: ({@value, @scopes, @isAtomic, @bufferDelta, @isHardTab}) -> @screenDelta = @value.length @bufferDelta ?= @screenDelta - @hasSurrogatePairs = textUtils.hasSurrogatePairs(@value) + @hasSurrogatePair = textUtils.hasSurrogatePair(@value) ### Public ### @@ -30,7 +30,7 @@ class Token [new Token(value: value1, scopes: @scopes), new Token(value: value2, scopes: @scopes)] breakOutAtomicTokens: (tabLength, breakOutLeadingWhitespace) -> - if @hasSurrogatePairs + if @hasSurrogatePair outputTokens = [] for token in @breakOutSurrogatePairs() diff --git a/src/stdlib/text-utils.coffee b/src/stdlib/text-utils.coffee index ca3f4d043..5f1800f61 100644 --- a/src/stdlib/text-utils.coffee +++ b/src/stdlib/text-utils.coffee @@ -27,8 +27,7 @@ isSurrogatePair = (string, index) -> # Returns a {Number}. getCharacterCount = (string) -> count = string.length - for index in [0...string.length] when isSurrogatePair(string, index) - count-- + count-- for index in [0...string.length] when isSurrogatePair(string, index) count # Does the given string contain at least one surrogate pair? @@ -36,7 +35,7 @@ getCharacterCount = (string) -> # string - The {String} to check for the presence of surrogate pairs. # # Returns a {Boolean}. -hasSurrogatePairs = (string) -> +hasSurrogatePair = (string) -> string.length isnt getCharacterCount(string) -module.exports = {getCharacterCount, isSurrogatePair, hasSurrogatePairs} +module.exports = {getCharacterCount, isSurrogatePair, hasSurrogatePair}