Permalink
Browse files

Expose helper functions in twttr.txt namespace

regexSupplant, stringSupplant, and addCharsToCharClass are
all helpful functions for people working with the twttr.txt
regular expressions.
  • Loading branch information...
1 parent 87ca503 commit 89fcdd1e1581de1252c48c96ab10f47a5ad3a2c3 Justin de Vesine committed May 16, 2012
Showing with 6 additions and 0 deletions.
  1. +6 −0 twitter-text.js
View
6 twitter-text.js
@@ -53,13 +53,17 @@ if (typeof twttr === "undefined" || twttr === null) {
}), flags);
}
+ twttr.txt.regexSupplant = regexSupplant;
+
// simple string interpolation
function stringSupplant(str, values) {
return str.replace(/#\{(\w+)\}/g, function(match, name) {
return values[name] || "";
});
}
+ twttr.txt.stringSupplant = stringSupplant;
+
function addCharsToCharClass(charClass, start, end) {
var s = String.fromCharCode(start);
if (end !== start) {
@@ -69,6 +73,8 @@ if (typeof twttr === "undefined" || twttr === null) {
return charClass;
}
+ twttr.txt.addCharsToCharClass = addCharsToCharClass;
+
// Space is more than %20, U+3000 for example is the full-width space used with Kanji. Provide a short-hand
// to access both the list of characters and a pattern suitible for use with String#split
// Taken from: ActiveSupport::Multibyte::Handlers::UTF8Handler::UNICODE_WHITESPACE

0 comments on commit 89fcdd1

Please sign in to comment.