void FTPDirectoryTokenizer::parseAndAppendOneLine(const String& inputLine) { ListResult result; DeprecatedString depString = inputLine.deprecatedString(); const char* line = depString.ascii(); FTPEntryType typeResult = parseOneFTPLine(line, m_listState, result); // FTPMiscEntry is a comment or usage statistic which we don't care about, and junk is invalid data - bail in these 2 cases if (typeResult == FTPMiscEntry || typeResult == FTPJunkEntry) return; String filename(result.filename, result.filenameLength); if (result.type == FTPDirectoryEntry) { filename.append("/"); // We have no interest in linking to "current directory" if (filename == "./") return; } LOG(FTP, "Appending entry - %s, %s", filename.ascii().data(), result.fileSize.ascii().data()); appendEntry(filename, processFilesizeString(result.fileSize, result.type == FTPDirectoryEntry), processFileDateString(result.modifiedTime), result.type == FTPDirectoryEntry); }
String cookies(const KURL& url) { #if USE(CFNETWORK) CFHTTPCookieStorageRef defaultCookieStorage = wkGetDefaultHTTPCookieStorage(); if (!defaultCookieStorage) return String(); String cookieString; RetainPtr<CFURLRef> urlCF(AdoptCF, url.createCFURL()); bool secure = equalIgnoringCase(url.protocol(), "https"); RetainPtr<CFArrayRef> cookiesCF(AdoptCF, CFHTTPCookieStorageCopyCookiesForURL(defaultCookieStorage, urlCF.get(), secure)); RetainPtr<CFDictionaryRef> headerCF(AdoptCF, CFHTTPCookieCopyRequestHeaderFields(kCFAllocatorDefault, cookiesCF.get())); return (CFStringRef)CFDictionaryGetValue(headerCF.get(), s_cookieCF); #else DeprecatedString str = url.url(); str.append((UChar)'\0'); DWORD count = str.length(); InternetGetCookie((UChar*)str.unicode(), 0, 0, &count); if (count <= 1) // Null terminator counts as 1. return String(); UChar* buffer = new UChar[count]; InternetGetCookie((UChar*)str.unicode(), 0, buffer, &count); String& result = String(buffer, count-1); // Ignore the null terminator. delete[] buffer; return result; #endif }
void ResourceHandleManager::add(ResourceHandle* job, FrameQtClient* frameClient) { ResourceHandleInternal* d = job->getInternal(); DeprecatedString url = d->m_request.url().url(); KIO::Job* kioJob = 0; if (job->method() == "POST") { DeprecatedString postData = job->postData().flattenToString().deprecatedString(); QByteArray postDataArray(postData.ascii(), postData.length()); kioJob = KIO::http_post(KUrl(url), postDataArray, false); kioJob->addMetaData("PropagateHttpHeader", "true"); kioJob->addMetaData("content-type", "Content-Type: application/x-www-form-urlencoded"); } else kioJob = KIO::get(KUrl(url), false, false); Q_ASSERT(kioJob != 0); QObject::connect(kioJob, SIGNAL(data(KIO::Job*, const QByteArray&)), this, SLOT(slotData(KIO::Job*, const QByteArray&))); QObject::connect(kioJob, SIGNAL(mimetype(KIO::Job*, const QString&)), this, SLOT(slotMimetype(KIO::Job*, const QString&))); QObject::connect(kioJob, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*))); m_jobToKioMap.insert(job, kioJob); m_kioToJobMap.insert(kioJob, job); if (!m_frameClient) m_frameClient = frameClient; else ASSERT(m_frameClient == frameClient); }
void SVGPatternElement::fillAttributesFromReferencePattern(const SVGPatternElement* target, KCanvasMatrix& patternTransformMatrix) const { DeprecatedString ref = String(href()->baseVal()).deprecatedString(); KRenderingPaintServer *refServer = getPaintServerById(document(), ref.mid(1)); if (!refServer || refServer->type() != PS_PATTERN) return; KRenderingPaintServerPattern *refPattern = static_cast<KRenderingPaintServerPattern *>(refServer); if (!hasAttribute(SVGNames::patternUnitsAttr)) { const AtomicString& value = target->getAttribute(SVGNames::patternUnitsAttr); if (value == "userSpaceOnUse") patternUnits()->setBaseVal(SVG_UNIT_TYPE_USERSPACEONUSE); else if (value == "objectBoundingBox") patternUnits()->setBaseVal(SVG_UNIT_TYPE_OBJECTBOUNDINGBOX); } if (!hasAttribute(SVGNames::patternContentUnitsAttr)) { const AtomicString& value = target->getAttribute(SVGNames::patternContentUnitsAttr); if (value == "userSpaceOnUse") patternContentUnits()->setBaseVal(SVG_UNIT_TYPE_USERSPACEONUSE); else if (value == "objectBoundingBox") patternContentUnits()->setBaseVal(SVG_UNIT_TYPE_OBJECTBOUNDINGBOX); } if (!hasAttribute(SVGNames::patternTransformAttr)) patternTransformMatrix = refPattern->patternTransform(); }
void Color::setNamedColor(const String& name) { DeprecatedString dname = name.deprecatedString(); const NamedColor* foundColor = dname.isAllASCII() ? findColor(dname.latin1(), dname.length()) : 0; color = foundColor ? foundColor->RGBValue : 0; color |= 0xFF000000; valid = foundColor; }
// FIXME: Can't really do this work without taking whitespace mode into account. // This means that eventually this function needs to be eliminated or at least have // its parameters changed because it can't do its work on the string without knowing // what parts are in what whitespace mode. DeprecatedString convertHTMLTextToInterchangeFormat(const DeprecatedString &in) { DeprecatedString s; unsigned int i = 0; unsigned int consumed = 0; while (i < in.length()) { consumed = 1; if (isCollapsibleWhitespace(in[i].unicode())) { // count number of adjoining spaces unsigned int j = i + 1; while (j < in.length() && isCollapsibleWhitespace(in[j].unicode())) j++; unsigned int count = j - i; consumed = count; while (count) { unsigned int add = count % 3; switch (add) { case 0: s += convertedSpaceString(); s += ' '; s += convertedSpaceString(); add = 3; break; case 1: if (i == 0 || i + 1 == in.length()) // at start or end of string s += convertedSpaceString(); else s += ' '; break; case 2: if (i == 0) { // at start of string s += convertedSpaceString(); s += ' '; } else if (i + 2 == in.length()) { // at end of string s += convertedSpaceString(); s += convertedSpaceString(); } else { s += convertedSpaceString(); s += ' '; } break; } count -= add; } } else { s += in[i]; } i += consumed; } return s; }
bool operator==(const String& a, const DeprecatedString& b) { unsigned l = a.length(); if (l != b.length()) return false; if (!memcmp(a.characters(), b.unicode(), l * sizeof(UChar))) return true; return false; }
void setCookies(const KURL& url, const KURL& policyURL, const String& value) { DeprecatedString str = url.url(); DeprecatedString result("Set-Cookie:"); DeprecatedString val = value.deprecatedString(); //add everything in the cookie result.append(val); //Check if it had appended domain, path bool noDomainSet = !val.contains(DeprecatedString("domain=")); bool noPathSet = !val.contains(DeprecatedString("path=")); if(noDomainSet || noPathSet) { char pathBuffer[SIZE_OF_LATIN1_BUFFERS]; char domainBuffer[SIZE_OF_LATIN1_BUFFERS]; int tl_domainLocationInUrlBegins = str.find("://") + SIZE_OF_COLONSLASHSLASH; int tl_domainLocationInUrlEnds = str.find("/",tl_domainLocationInUrlBegins) - 1; result.append(';'); if(noDomainSet) { str.copyLatin1(domainBuffer, tl_domainLocationInUrlBegins, tl_domainLocationInUrlEnds - tl_domainLocationInUrlBegins + 1); domainBuffer[tl_domainLocationInUrlEnds - tl_domainLocationInUrlBegins + 1] = '\0'; result.append(DeprecatedString(" domain=")); result.append(DeprecatedString::fromLatin1(domainBuffer)); result.append(';'); } if(noPathSet) { int tl_pathLocationInUrlEnds = str.findRev("/"); str.copyLatin1(pathBuffer, tl_domainLocationInUrlEnds + 1, // 1 because it'll include '/' tl_pathLocationInUrlEnds - tl_domainLocationInUrlEnds ); pathBuffer[tl_pathLocationInUrlEnds = tl_domainLocationInUrlEnds] = '\0'; result.append(DeprecatedString(" path=")); result.append(DeprecatedString::fromLatin1(pathBuffer)); result.append(';'); } } if(val.startsWith(DeprecatedString("https://"))) { result.append(DeprecatedString(" secure")); } //Connect with Runtime. // WebKitApollo::g_HostFunctions->setJavaScriptCookie(result.latin1()); }
String::String(const DeprecatedString& str) { if (str.isNull()) return; if (str.isEmpty()) m_impl = StringImpl::empty(); else m_impl = new StringImpl(reinterpret_cast<const UChar*>(str.unicode()), str.length()); }
/** * Test a POST form transfer */ static void TestNetworkPostTransfer() { // FIXME Setup a http server to serve the files TestManager::AssertTrue("No web server setup for the tests", false); return; const std::string aURL(TEST_WEB_SITE"testpostwithparam.php"); std::string aPath = TestManager::GetInstance().getPath() + "NetworkTests/Refs/testpostwithparam.html"; const std::string aRef(aPath); BIResourceHandleManager* aResourceHandleManager = getBIResourceHandleManager(); TestManager::AssertTrue("Transfer Job Manager obtained", aResourceHandleManager != NULL); std::string aFileName; GetTemporaryUnexistingFileName("/tmp/transfer", ".txt", aFileName); TestResourceHandleClient aTestResourceHandleClient(aFileName); FormData formData; DeprecatedString aParams; aParams = "param1=toto¶m2=kiki"; formData.appendData( static_cast<const void *> (aParams.ascii()), aParams.length() ); ResourceRequest aResourceRequest = ResourceRequest(static_cast<const KURL&> (aURL.c_str())); aResourceRequest.setHTTPMethod("POST"); aResourceRequest.setHTTPReferrer(TEST_WEB_SITE); aResourceRequest.setHTTPBody(formData.copy());; RefPtr<BIResourceHandle> aResourceHandle = BIResourceHandle::create(aResourceRequest, &aTestResourceHandleClient, 0, false, false, false); TestManager::AssertTrue("FormData flatten", aResourceRequest.httpBody()->flattenToString() == "param1=toto¶m2=kiki" ); TestManager::AssertTrue("Form data with correct element", aResourceRequest.httpBody()->elements().size() == 1 ); TestManager::AssertTrue("Correct Metadata", aResourceRequest.httpReferrer() == TEST_WEB_SITE ); TestManager::AssertTrue("Correct Method", aResourceHandle->method() == "POST"); gTransferFileCount = 1; // Wait for the end of the transfer. gTimeout = false; WebCore::Timer<NetworkTest> aTimeoutTimer(NULL,&NetworkTest::TimeoutCallback); aTimeoutTimer.startOneShot(20); // timeout in 20s BIEventLoop* aEventLoop = BAL::getBIEventLoop(); BIEvent* event; while( gTransferFileCount && !gTimeout ) { aEventLoop->WaitEvent(event); } TestManager::AssertTrue("Transfer done", !gTransferFileCount ); BALFileComparison aFileComparison; bool bEqual = aFileComparison.AreEqual( aFileName, aRef ); TestManager::AssertTrue("File as expected", bEqual ); unlink( aFileName.c_str() ); }
static inline void mapAttributeToCSSProperty(HashMap<AtomicStringImpl*, int>* propertyNameToIdMap, const QualifiedName& attrName, const char* cssPropertyName = 0) { int propertyId = 0; if (cssPropertyName) propertyId = cssPropertyIdForName(cssPropertyName, strlen(cssPropertyName)); else { DeprecatedString propertyName = attrName.localName().deprecatedString(); propertyId = cssPropertyIdForName(propertyName.ascii(), propertyName.length()); } ASSERT(propertyId > 0); propertyNameToIdMap->set(attrName.localName().impl(), propertyId); }
String HTMLOptGroupElement::groupLabelText() { DeprecatedString itemText = getAttribute(labelAttr).deprecatedString(); itemText.replace('\\', document()->backslashAsCurrencySymbol()); // In WinIE, leading and trailing whitespace is ignored in options and optgroups. We match this behavior. itemText = itemText.stripWhiteSpace(); // We want to collapse our whitespace too. This will match other browsers. itemText = itemText.simplifyWhiteSpace(); return itemText; }
DeprecatedString CharacterIterator::string(int numChars) { DeprecatedString result; result.reserve(numChars); while (numChars > 0 && !atEnd()) { int runSize = min(numChars, length()); result.append(reinterpret_cast<const DeprecatedChar*>(characters()), runSize); numChars -= runSize; advance(runSize); } return result; }
void write(TextStream &ts, const RenderPath &path, int indent) { writeIndent(ts, indent); ts << path.renderName(); if (path.element()) { DeprecatedString tagName = getTagName(path.element()); if (!tagName.isEmpty()) ts << " {" << tagName << "}"; } ts << path << endl; }
// We strip BOM characters because they can show up both at the start of content // and inside content, and we never want them to end up in the decoded text. void StreamingTextDecoderICU::appendOmittingBOM(DeprecatedString& s, const UChar* characters, int byteCount) { ASSERT(byteCount % sizeof(UChar) == 0); int start = 0; int characterCount = byteCount / sizeof(UChar); for (int i = 0; i != characterCount; ++i) { if (BOM == characters[i]) { if (start != i) s.append(reinterpret_cast<const DeprecatedChar*>(&characters[start]), i - start); start = i + 1; } } if (start != characterCount) s.append(reinterpret_cast<const DeprecatedChar*>(&characters[start]), characterCount - start); }
void write(TextStream &ts, const RenderSVGContainer &container, int indent) { writeIndent(ts, indent); ts << container.renderName(); if (container.element()) { DeprecatedString tagName = getTagName(container.element()); if (!tagName.isEmpty()) ts << " {" << tagName << "}"; } ts << container << endl; for (RenderObject *child = container.firstChild(); child != NULL; child = child->nextSibling()) write(ts, *child, indent + 1); }
DeprecatedStringList DeprecatedStringList::split(const DeprecatedString &separator, const DeprecatedString &s, bool allowEmptyEntries) { DeprecatedStringList result; int startPos = 0; int endPos; while ((endPos = s.find(separator, startPos)) != -1) { if (allowEmptyEntries || startPos != endPos) result.append(s.mid(startPos, endPos - startPos)); startPos = endPos + separator.length(); } if (allowEmptyEntries || startPos != (int)s.length()) result.append(s.mid(startPos)); return result; }
int RegularExpression::search(const DeprecatedString &str, int startFrom) const { if (startFrom < 0) { startFrom = str.length() - startFrom; } return match(str, startFrom, NULL); }
String cookies(const KURL& url) { DeprecatedString str = url.url(); str.append((UChar)'\0'); DWORD count; InternetGetCookie((UChar*)str.unicode(), 0, 0, &count); if (count <= 1) // Null terminator counts as 1. return String(); UChar* buffer = new UChar[count]; InternetGetCookie((UChar*)str.unicode(), 0, buffer, &count); String& result = String(buffer, count-1); // Ignore the null terminator. delete buffer; return result; }
void SVGPolyParser::parsePoints(const DeprecatedString &s) const { if (!s.isEmpty()) { DeprecatedString pointData = s; pointData = pointData.replace(',', ' '); pointData = pointData.simplifyWhiteSpace(); const char* currSegment = pointData.latin1(); const char* eoString = pointData.latin1() + pointData.length(); int segmentNum = 0; while (currSegment < eoString) { const char* prevSegment = currSegment; double xPos = 0; currSegment = parseCoord(currSegment, xPos); if (currSegment == prevSegment) break; if (*currSegment == ',' || *currSegment == ' ') currSegment++; prevSegment = currSegment; double yPos = 0; currSegment = parseCoord(currSegment, yPos); if (currSegment == prevSegment) break; svgPolyTo(xPos, yPos, segmentNum++); if (*currSegment == ' ') currSegment++; } } }
void SVGPatternElement::notifyAttributeChange() const { if (!m_paintServer || !m_paintServer->activeClient() || m_ignoreAttributeChanges) return; IntSize newSize = IntSize(lroundf(width()->baseVal()->value()), lroundf(height()->baseVal()->value())); if (m_tile && (m_tile->size() == newSize) || newSize.width() < 1 || newSize.height() < 1) return; m_ignoreAttributeChanges = true; // FIXME: This whole "target" idea seems completely broken to me // basically it seems we're effectively trying to change the "this" pointer // for the rest of the method... why don't we just? Or better yet, why don't // we call some method on the "target" and each target in the chain? -- ECS 11/21/05 // Find first pattern def that has children const SVGPatternElement* target = this; const Node *test = this; while(test && !test->hasChildNodes()) { DeprecatedString ref = String(target->href()->baseVal()).deprecatedString(); test = ownerDocument()->getElementById(String(ref.mid(1)).impl()); if (test && test->hasTagName(SVGNames::patternTag)) target = static_cast<const SVGPatternElement* >(test); } unsigned short savedPatternUnits = patternUnits()->baseVal(); unsigned short savedPatternContentUnits = patternContentUnits()->baseVal(); KCanvasMatrix patternTransformMatrix; if (patternTransform()->baseVal()->numberOfItems() > 0) patternTransformMatrix = KCanvasMatrix(patternTransform()->baseVal()->consolidate()->matrix()->matrix()); fillAttributesFromReferencePattern(target, patternTransformMatrix); drawPatternContentIntoTile(target, newSize, patternTransformMatrix); patternUnits()->setBaseVal(savedPatternUnits); patternContentUnits()->setBaseVal(savedPatternContentUnits); notifyClientsToRepaint(); m_ignoreAttributeChanges = false; }
void SVGLength::setValueAsString(const String& s) { if(s.isEmpty()) return; DeprecatedString valueAsQString = s.deprecatedString(); double convertedNumber = 0; const char *start = valueAsQString.latin1(); const char *end = parseCoord(start, convertedNumber); m_valueInSpecifiedUnits = convertedNumber; unsigned int diff = end - start; if (diff < valueAsQString.length()) { if (s.endsWith(UnitText[SVG_LENGTHTYPE_PX])) m_unitType = SVG_LENGTHTYPE_PX; else if (s.endsWith(UnitText[SVG_LENGTHTYPE_CM])) m_unitType = SVG_LENGTHTYPE_CM; else if (s.endsWith(UnitText[SVG_LENGTHTYPE_PC])) m_unitType = SVG_LENGTHTYPE_PC; else if (s.endsWith(UnitText[SVG_LENGTHTYPE_MM])) m_unitType = SVG_LENGTHTYPE_MM; else if (s.endsWith(UnitText[SVG_LENGTHTYPE_IN])) m_unitType = SVG_LENGTHTYPE_IN; else if (s.endsWith(UnitText[SVG_LENGTHTYPE_PT])) m_unitType = SVG_LENGTHTYPE_PT; else if (s.endsWith(UnitText[SVG_LENGTHTYPE_PERCENTAGE])) m_unitType = SVG_LENGTHTYPE_PERCENTAGE; else if (s.endsWith(UnitText[SVG_LENGTHTYPE_EMS])) m_unitType = SVG_LENGTHTYPE_EMS; else if (s.endsWith(UnitText[SVG_LENGTHTYPE_EXS])) m_unitType = SVG_LENGTHTYPE_EXS; else if (s.isEmpty()) m_unitType = SVG_LENGTHTYPE_NUMBER; else m_unitType = SVG_LENGTHTYPE_UNKNOWN; } else m_unitType = SVG_LENGTHTYPE_PX; updateValue(); }
void RegularExpression::Private::compile(bool caseSensitive, bool glob) { DeprecatedString p; if (glob) { p = RegExpFromGlob(pattern); } else { p = pattern; } // Note we don't honor the Qt syntax for various character classes. If we convert // to a different underlying engine, we may need to change client code that relies // on the regex syntax (see FrameMac.mm for a couple examples). const char *errorMessage; int errorOffset; regex = pcre_compile(reinterpret_cast<const uint16_t *>(p.unicode()), p.length(), caseSensitive ? 0 : PCRE_CASELESS, &errorMessage, &errorOffset, NULL); if (regex == NULL) { LOG_ERROR("RegularExpression: pcre_compile failed with '%s'", errorMessage); } }
void setCookies(const KURL& url, const KURL& policyURL, const String& value) { #if USE(CFNETWORK) CFHTTPCookieStorageRef defaultCookieStorage = wkGetDefaultHTTPCookieStorage(); if (!defaultCookieStorage) return; RetainPtr<CFURLRef> urlCF(AdoptCF, url.createCFURL()); RetainPtr<CFURLRef> policyURLCF(AdoptCF, policyURL.createCFURL()); // <http://bugzilla.opendarwin.org/show_bug.cgi?id=6531>, <rdar://4409034> // cookiesWithResponseHeaderFields doesn't parse cookies without a value String cookieString = value.contains('=') ? value : value + "="; RetainPtr<CFStringRef> cookieStringCF(AdoptCF, cookieString.createCFString()); RetainPtr<CFDictionaryRef> headerFieldsCF(AdoptCF, CFDictionaryCreate(kCFAllocatorDefault, (const void**)&s_setCookieKeyCF, (const void**)&cookieStringCF, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); RetainPtr<CFArrayRef> cookiesCF(AdoptCF, CFHTTPCookieCreateWithResponseHeaderFields(kCFAllocatorDefault, headerFieldsCF.get(), urlCF.get())); CFHTTPCookieStorageSetCookies(defaultCookieStorage, cookiesCF.get(), urlCF.get(), policyURLCF.get()); #else // FIXME: Deal with the policy URL. DeprecatedString str = url.url(); str.append((UChar)'\0'); DeprecatedString val = value.deprecatedString(); val.append((UChar)'\0'); InternetSetCookie((UChar*)str.unicode(), 0, (UChar*)val.unicode()); #endif }
String cookies(const KURL& url) { DeprecatedString str = url.url(); char domainBuffer[SIZE_OF_LATIN1_BUFFERS]; char pathBuffer[SIZE_OF_LATIN1_BUFFERS]; int tl_domainLocationInUrlBegins = str.find("://") + SIZE_OF_COLONSLASHSLASH; int tl_domainLocationInUrlEnds = str.find("/",tl_domainLocationInUrlBegins) - 1; int tl_pathLocationInUrlEnds = str.findRev("/"); strncpy(domainBuffer, str.ascii() + tl_domainLocationInUrlBegins, tl_domainLocationInUrlEnds - tl_domainLocationInUrlBegins + 1); domainBuffer[tl_domainLocationInUrlEnds - tl_domainLocationInUrlBegins + 1] = '\0'; strncpy(pathBuffer, str.ascii() + tl_domainLocationInUrlEnds + 1, tl_pathLocationInUrlEnds - tl_domainLocationInUrlEnds); pathBuffer[tl_pathLocationInUrlEnds - tl_domainLocationInUrlEnds] = '\0'; char* cookStr = WebKitApollo::g_HostFunctions->getJavaScriptCookies(domainBuffer,pathBuffer); if(!cookStr) { return String(); } String cookieString(cookStr); ::free(cookStr); return cookieString; }
void HTMLTextAreaElement::setValue(const String& value) { // Code elsewhere normalizes line endings added by the user via the keyboard or pasting. // We must normalize line endings coming from JS. DeprecatedString valueWithNormalizedLineEndings = value.deprecatedString(); valueWithNormalizedLineEndings.replace("\r\n", "\n"); valueWithNormalizedLineEndings.replace("\r", "\n"); m_value = valueWithNormalizedLineEndings; setValueMatchesRenderer(); if (inDocument()) document()->updateRendering(); if (renderer()) renderer()->updateFromElement(); // Set the caret to the end of the text value. if (document()->focusedNode() == this) { unsigned endOfString = m_value.length(); setSelectionRange(endOfString, endOfString); } setChanged(); }
void setCookies(const KURL& url, const KURL& policyURL, const String& value) { // FIXME: Deal with the policy URL. DeprecatedString str = url.url(); str.append((UChar)'\0'); DeprecatedString val = value.deprecatedString(); val.append((UChar)'\0'); InternetSetCookie((UChar*)str.unicode(), 0, (UChar*)val.unicode()); }
String HTMLOptionElement::optionText() { DeprecatedString itemText = text().deprecatedString(); if (itemText.isEmpty()) itemText = getAttribute(labelAttr).deprecatedString(); itemText.replace('\\', document()->backslashAsCurrencySymbol()); // In WinIE, leading and trailing whitespace is ignored in options and optgroups. We match this behavior. itemText = itemText.stripWhiteSpace(); // We want to collapse our whitespace too. This will match other browsers. itemText = itemText.simplifyWhiteSpace(); if (parentNode() && parentNode()->hasTagName(optgroupTag)) itemText.prepend(" "); return itemText; }
static DeprecatedString RegExpFromGlob(DeprecatedString glob) { DeprecatedString result = glob; // escape regexp metacharacters which are NOT glob metacharacters result.replace(RegularExpression("\\\\"), "\\\\"); result.replace(RegularExpression("\\."), "\\."); result.replace(RegularExpression("\\+"), "\\+"); result.replace(RegularExpression("\\$"), "\\$"); // FIXME: incorrect for ^ inside bracket group result.replace(RegularExpression("\\^"), "\\^"); // translate glob metacharacters into regexp metacharacters result.replace(RegularExpression("\\*"), ".*"); result.replace(RegularExpression("\\?"), "."); // Require the glob to match the whole string result = "^" + result + "$"; return result; }
void SVGPathParser::parseSVG( const DeprecatedString &s, bool process ) { if(!s.isEmpty()) { DeprecatedString d = s; d = d.replace(',', ' '); d = d.simplifyWhiteSpace(); const char *ptr = d.latin1(); const char *end = d.latin1() + d.length() + 1; double contrlx, contrly, curx, cury, subpathx, subpathy, tox, toy, x1, y1, x2, y2, xc, yc; double px1, py1, px2, py2, px3, py3; bool relative, closed = true; char command = *(ptr++), lastCommand = ' '; subpathx = subpathy = curx = cury = contrlx = contrly = 0.0; while( ptr < end ) { if( *ptr == ' ' ) ptr++; relative = false; //std::cout << "Command : " << command << std::endl; switch( command ) { case 'm': relative = true; case 'M': { ptr = parseCoord( ptr, tox ); ptr = parseCoord( ptr, toy ); if( process ) { subpathx = curx = relative ? curx + tox : tox; subpathy = cury = relative ? cury + toy : toy; svgMoveTo( curx, cury, closed ); } else svgMoveTo( tox, toy, closed, !relative ); closed = false; break; } case 'l': relative = true; case 'L': { ptr = parseCoord( ptr, tox ); ptr = parseCoord( ptr, toy ); if( process ) { curx = relative ? curx + tox : tox; cury = relative ? cury + toy : toy; svgLineTo( curx, cury ); } else svgLineTo( tox, toy, !relative ); break; } case 'h': { ptr = parseCoord( ptr, tox ); if( process ) { curx = curx + tox; svgLineTo( curx, cury ); } else svgLineToHorizontal( tox, false ); break; } case 'H': { ptr = parseCoord( ptr, tox ); if( process ) { curx = tox; svgLineTo( curx, cury ); } else svgLineToHorizontal( tox ); break; } case 'v': { ptr = parseCoord( ptr, toy ); if( process ) { cury = cury + toy; svgLineTo( curx, cury ); } else svgLineToVertical( toy, false ); break; } case 'V': { ptr = parseCoord( ptr, toy ); if( process ) { cury = toy; svgLineTo( curx, cury ); } else svgLineToVertical( toy ); break; } case 'z': case 'Z': { // reset curx, cury for next path if( process ) { curx = subpathx; cury = subpathy; } closed = true; svgClosePath(); break; } case 'c': relative = true; case 'C': { ptr = parseCoord( ptr, x1 ); ptr = parseCoord( ptr, y1 ); ptr = parseCoord( ptr, x2 ); ptr = parseCoord( ptr, y2 ); ptr = parseCoord( ptr, tox ); ptr = parseCoord( ptr, toy ); if( process ) { px1 = relative ? curx + x1 : x1; py1 = relative ? cury + y1 : y1; px2 = relative ? curx + x2 : x2; py2 = relative ? cury + y2 : y2; px3 = relative ? curx + tox : tox; py3 = relative ? cury + toy : toy; svgCurveToCubic( px1, py1, px2, py2, px3, py3 ); contrlx = relative ? curx + x2 : x2; contrly = relative ? cury + y2 : y2; curx = relative ? curx + tox : tox; cury = relative ? cury + toy : toy; } else svgCurveToCubic( x1, y1, x2, y2, tox, toy, !relative ); break; } case 's': relative = true; case 'S': { ptr = parseCoord( ptr, x2 ); ptr = parseCoord( ptr, y2 ); ptr = parseCoord( ptr, tox ); ptr = parseCoord( ptr, toy ); if(!(lastCommand == 'c' || lastCommand == 'C' || lastCommand == 's' || lastCommand == 'S')) { contrlx = curx; contrly = cury; } if( process ) { px1 = 2 * curx - contrlx; py1 = 2 * cury - contrly; px2 = relative ? curx + x2 : x2; py2 = relative ? cury + y2 : y2; px3 = relative ? curx + tox : tox; py3 = relative ? cury + toy : toy; svgCurveToCubic( px1, py1, px2, py2, px3, py3 ); contrlx = relative ? curx + x2 : x2; contrly = relative ? cury + y2 : y2; curx = relative ? curx + tox : tox; cury = relative ? cury + toy : toy; } else svgCurveToCubicSmooth( x2, y2, tox, toy, !relative ); break; } case 'q': relative = true; case 'Q': { ptr = parseCoord( ptr, x1 ); ptr = parseCoord( ptr, y1 ); ptr = parseCoord( ptr, tox ); ptr = parseCoord( ptr, toy ); if( process ) { px1 = relative ? (curx + 2 * (x1 + curx)) * (1.0 / 3.0) : (curx + 2 * x1) * (1.0 / 3.0); py1 = relative ? (cury + 2 * (y1 + cury)) * (1.0 / 3.0) : (cury + 2 * y1) * (1.0 / 3.0); px2 = relative ? ((curx + tox) + 2 * (x1 + curx)) * (1.0 / 3.0) : (tox + 2 * x1) * (1.0 / 3.0); py2 = relative ? ((cury + toy) + 2 * (y1 + cury)) * (1.0 / 3.0) : (toy + 2 * y1) * (1.0 / 3.0); px3 = relative ? curx + tox : tox; py3 = relative ? cury + toy : toy; svgCurveToCubic( px1, py1, px2, py2, px3, py3 ); contrlx = relative ? curx + x1 : x1; contrly = relative ? cury + y1 : y1; curx = relative ? curx + tox : tox; cury = relative ? cury + toy : toy; } else svgCurveToQuadratic( x1, y1, tox, toy, !relative ); break; } case 't': relative = true; case 'T': { ptr = parseCoord(ptr, tox); ptr = parseCoord(ptr, toy); if(!(lastCommand == 'q' || lastCommand == 'Q' || lastCommand == 't' || lastCommand == 'T')) { contrlx = curx; contrly = cury; } if( process ) { xc = 2 * curx - contrlx; yc = 2 * cury - contrly; px1 = relative ? (curx + 2 * xc) * (1.0 / 3.0) : (curx + 2 * xc) * (1.0 / 3.0); py1 = relative ? (cury + 2 * yc) * (1.0 / 3.0) : (cury + 2 * yc) * (1.0 / 3.0); px2 = relative ? ((curx + tox) + 2 * xc) * (1.0 / 3.0) : (tox + 2 * xc) * (1.0 / 3.0); py2 = relative ? ((cury + toy) + 2 * yc) * (1.0 / 3.0) : (toy + 2 * yc) * (1.0 / 3.0); px3 = relative ? curx + tox : tox; py3 = relative ? cury + toy : toy; svgCurveToCubic( px1, py1, px2, py2, px3, py3 ); contrlx = xc; contrly = yc; curx = relative ? curx + tox : tox; cury = relative ? cury + toy : toy; } else svgCurveToQuadraticSmooth( tox, toy, !relative ); break; } case 'a': relative = true; case 'A': { bool largeArc, sweep; double angle, rx, ry; ptr = parseCoord( ptr, rx ); ptr = parseCoord( ptr, ry ); ptr = parseCoord( ptr, angle ); ptr = parseCoord( ptr, tox ); largeArc = tox == 1; ptr = parseCoord( ptr, tox ); sweep = tox == 1; ptr = parseCoord( ptr, tox ); ptr = parseCoord( ptr, toy ); // Spec: radii are nonnegative numbers rx = fabs(rx); ry = fabs(ry); if( process ) calculateArc( relative, curx, cury, angle, tox, toy, rx, ry, largeArc, sweep ); else svgArcTo( tox, toy, rx, ry, angle, largeArc, sweep, !relative ); break; } default: // FIXME: An error should go to the JavaScript console, or the like. return; } lastCommand = command; if(*ptr == '+' || *ptr == '-' || (*ptr >= '0' && *ptr <= '9')) { // there are still coords in this command if(command == 'M') command = 'L'; else if(command == 'm') command = 'l'; } else command = *(ptr++); if( lastCommand != 'C' && lastCommand != 'c' && lastCommand != 'S' && lastCommand != 's' && lastCommand != 'Q' && lastCommand != 'q' && lastCommand != 'T' && lastCommand != 't' ) { contrlx = curx; contrly = cury; } } } }