Changeset 89895 in webkit for trunk/Source/JavaScriptCore/runtime/RegExpObject.cpp
- Timestamp:
- Jun 27, 2011, 10:55:45 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/runtime/RegExpObject.cpp
r87346 r89895 30 30 #include "RegExpConstructor.h" 31 31 #include "RegExpPrototype.h" 32 #include "UStringBuilder.h" 32 33 #include "UStringConcatenate.h" 33 34 #include <wtf/PassOwnPtr.h> … … 112 113 JSValue regExpObjectSource(ExecState* exec, JSValue slotBase, const Identifier&) 113 114 { 114 return jsString(exec, asRegExpObject(slotBase)->regExp()->pattern()); 115 UString pattern = asRegExpObject(slotBase)->regExp()->pattern(); 116 117 size_t forwardSlashPosition = pattern.find('/'); 118 if (forwardSlashPosition == notFound) 119 return jsString(exec, pattern); 120 121 // 'completed' tracks the length of original pattern already copied 122 // into the result buffer. 123 size_t completed = 0; 124 UStringBuilder result; 125 126 do { 127 // 'slashesPosition' points to the first (of possibly zero) backslash 128 // prior to the forwards slash. 129 size_t slashesPosition = forwardSlashPosition; 130 while (slashesPosition && pattern[slashesPosition - 1] == '\\') 131 --slashesPosition; 132 133 // Check whether the number of backslashes is odd or even - 134 // if odd, the forwards slash is already escaped, so we mustn't 135 // double escape it. 136 if ((forwardSlashPosition - slashesPosition) & 1) 137 result.append(pattern.substringSharingImpl(completed, forwardSlashPosition + 1)); 138 else { 139 result.append(pattern.substringSharingImpl(completed, forwardSlashPosition)); 140 result.append("\\/"); 141 } 142 completed = forwardSlashPosition + 1; 143 144 forwardSlashPosition = pattern.find('/', completed); 145 } while (forwardSlashPosition != notFound); 146 147 // Copy in the remainder of the pattern to the buffer. 148 result.append(pattern.substringSharingImpl(completed)); 149 return jsString(exec, result.toUString()); 115 150 } 116 151
Note:
See TracChangeset
for help on using the changeset viewer.