adium 2614:490052ed56a6: New array for regexp escaping. Thanks ...
commits at adium.im
commits at adium.im
Sat Aug 22 02:07:04 UTC 2009
details: http://hg.adium.im/adium/rev/490052ed56a6
revision: 2614:490052ed56a6
author: Stephen Holt <sholt at adium.im>
date: Fri Aug 21 22:10:39 2009 -0400
New array for regexp escaping. Thanks to boredzo for catching this.
diffs (74 lines):
diff -r cad79e14366e -r 490052ed56a6 Frameworks/AIUtilities Framework/Source/AIStringAdditions.m
--- a/Frameworks/AIUtilities Framework/Source/AIStringAdditions.m Fri Aug 21 15:51:20 2009 -0400
+++ b/Frameworks/AIUtilities Framework/Source/AIStringAdditions.m Fri Aug 21 22:10:39 2009 -0400
@@ -651,34 +651,44 @@
return result;
}
+static enum characterNatureMask regexpCharacterNature[USHRT_MAX+1] = {
+//this array is initialised such that the space character (0x20)
+// does not have the whitespace nature.
+//this was done for brevity, as the entire array is bzeroed and then
+// properly initialised in -stringByEscapingForShell below.
+0,0,0,0, 0,0,0,0, //0x00..0x07
+0,0,0,0, 0,0,0,0, //0x08..0x0f
+0,0,0,0, 0,0,0,0, //0x10..0x17
+0,0,0, //0x18..0x20
+};
- (NSString *)stringByEscapingForRegexp
{
- if (!(characterNature[' '] & whitespaceNature)) {
+ if (!(regexpCharacterNature[' '] & whitespaceNature)) {
//if space doesn't have the whitespace nature, clearly we need to build the nature array.
//first, set all characters to zero.
- bzero(&characterNature, sizeof(characterNature));
+ bzero(®expCharacterNature, sizeof(regexpCharacterNature));
//then memorise which characters have the whitespace nature.
- characterNature[' '] = whitespaceNature;
+ regexpCharacterNature[' '] = whitespaceNature;
//NOTE: if you give more characters the whitespace nature, be sure to
// update escapeNames below.
//finally, memorise which characters have the unsafe (for regexp) nature.
- characterNature['\\'] = regexpUnsafeNature;
- characterNature['/'] = regexpUnsafeNature;
- characterNature['|'] = regexpUnsafeNature;
- characterNature['.'] = regexpUnsafeNature;
- characterNature['*'] = regexpUnsafeNature;
- characterNature['+'] = regexpUnsafeNature;
- characterNature['?'] = regexpUnsafeNature;
- characterNature['{'] = regexpUnsafeNature;
- characterNature['}'] = regexpUnsafeNature;
- characterNature['('] = regexpUnsafeNature;
- characterNature[')'] = regexpUnsafeNature;
- characterNature['['] = regexpUnsafeNature;
- characterNature['$'] = regexpUnsafeNature;
- characterNature['^'] = regexpUnsafeNature;
+ regexpCharacterNature['\\'] = regexpUnsafeNature;
+ regexpCharacterNature['/'] = regexpUnsafeNature;
+ regexpCharacterNature['|'] = regexpUnsafeNature;
+ regexpCharacterNature['.'] = regexpUnsafeNature;
+ regexpCharacterNature['*'] = regexpUnsafeNature;
+ regexpCharacterNature['+'] = regexpUnsafeNature;
+ regexpCharacterNature['?'] = regexpUnsafeNature;
+ regexpCharacterNature['{'] = regexpUnsafeNature;
+ regexpCharacterNature['}'] = regexpUnsafeNature;
+ regexpCharacterNature['('] = regexpUnsafeNature;
+ regexpCharacterNature[')'] = regexpUnsafeNature;
+ regexpCharacterNature['['] = regexpUnsafeNature;
+ regexpCharacterNature['$'] = regexpUnsafeNature;
+ regexpCharacterNature['^'] = regexpUnsafeNature;
}
unsigned myLength = [self length];
@@ -721,7 +731,7 @@
for (; myLength--; ++i) {
SBEFR_BOUNDARY_GUARD;
- if (characterNature[*myBufPtr] & regexpUnsafeNature) {
+ if (regexpCharacterNature[*myBufPtr] & regexpUnsafeNature) {
//escape this character
buf[i++] = '\\';
SBEFR_BOUNDARY_GUARD;
More information about the commits
mailing list