Permalink
Browse files

Use Punctuation Blacklist for Typeahead Normalizer

Summary:
This changes the Typeahead normalizer to use a punctuation blacklist instead of stripping all non-alphanumeric characters. As the normalizer stands now, any international characters (e.g. Japanese characters) are stripped.

Reviewers: epriestley, jg

Test Plan:
  > JX.TypeaheadNormalizer.normalize('Get rid of the periods...')
  "get rid of the periods"
  > JX.TypeaheadNormalizer.normalize('ラジオ')
  "ラジオ"

Differential Revision: 924
  • Loading branch information...
1 parent eaefcdd commit 62ce6e6f8111497d5bee0cc3bd44c4a1902eb317 @yungsters yungsters committed Sep 13, 2011
Showing with 9 additions and 3 deletions.
  1. +9 −3 src/lib/control/typeahead/normalizer/TypeaheadNormalizer.js
@@ -4,16 +4,22 @@
* @javelin
*/
-
/**
* @group control
*/
JX.install('TypeaheadNormalizer', {
statics : {
+ /**
+ * Normalizes a string by lowercasing it and stripping out extra spaces
+ * and punctuation.
+ *
+ * @param string
+ * @return string Normalized string.
+ */
normalize : function(str) {
return ('' + str)
- .toLowerCase()
- .replace(/[^a-z0-9 ]/g, '')
+ .toLocaleLowerCase()
+ .replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()]/g, '')
.replace(/ +/g, ' ')
.replace(/^\s*|\s*$/g, '');
}

0 comments on commit 62ce6e6

Please sign in to comment.