Beispiel #1
0
// 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;
}
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);
}
static String cssPropertyName(const Identifier& propertyName, bool* hadPixelOrPosPrefix = 0)
{
    DeprecatedString prop = propertyName;

    int i = prop.length();

    if (!i)
        return prop;

    while (--i) {
        ::UChar c = prop[i].unicode();
        if (c >= 'A' && c <= 'Z')
            prop.insert(i, '-');
    }

    prop = prop.lower();

    if (hadPixelOrPosPrefix)
        *hadPixelOrPosPrefix = false;

    if (prop.startsWith("css-"))
        prop = prop.mid(4);
    else if (prop.startsWith("pixel-")) {
        prop = prop.mid(6);
        if (hadPixelOrPosPrefix)
            *hadPixelOrPosPrefix = true;
    } else if (prop.startsWith("pos-")) {
        prop = prop.mid(4);
        if (hadPixelOrPosPrefix)
            *hadPixelOrPosPrefix = true;
    } else if (prop.startsWith("khtml-") || prop.startsWith("apple-") || prop.startsWith("webkit-"))
        prop.insert(0, '-');

    return prop;
}
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
}
Beispiel #6
0
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 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);
}
Beispiel #8
0
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;
}
Beispiel #9
0
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;
}
Beispiel #10
0
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());
}
Beispiel #11
0
  /**
   * 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&param2=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&param2=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);
}
Beispiel #13
0
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();
}
Beispiel #14
0
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);
    }
}
Beispiel #15
0
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;
            }
        }
    }
}
Beispiel #16
0
DeprecatedCString StreamingTextDecoderICU::fromUnicode(const DeprecatedString &qcs, bool allowEntities)
{
    TextEncodingID encoding = m_encoding.effectiveEncoding().encodingID();

    if (encoding == WinLatin1Encoding && qcs.isAllLatin1())
        return qcs.latin1();

    if ((encoding == WinLatin1Encoding || encoding == UTF8Encoding || encoding == ASCIIEncoding) 
        && qcs.isAllASCII())
        return qcs.ascii();

    // FIXME: We should see if there is "force ASCII range" mode in ICU;
    // until then, we change the backslash into a yen sign.
    // Encoding will change the yen sign back into a backslash.
    DeprecatedString copy = qcs;
    copy.replace('\\', m_encoding.backslashAsCurrencySymbol());

    if (!m_converterICU)
        createICUConverter();
    if (!m_converterICU)
        return DeprecatedCString();

    // FIXME: when DeprecatedString buffer is latin1, it would be nice to
    // convert from that w/o having to allocate a unicode buffer

    char buffer[ConversionBufferSize];
    const UChar* source = reinterpret_cast<const UChar*>(copy.unicode());
    const UChar* sourceLimit = source + copy.length();

    UErrorCode err = U_ZERO_ERROR;
    DeprecatedString normalizedString;
    if (UNORM_YES != unorm_quickCheck(source, copy.length(), UNORM_NFC, &err)) {
        normalizedString.truncate(copy.length()); // normalization to NFC rarely increases the length, so this first attempt will usually succeed
        
        int32_t normalizedLength = unorm_normalize(source, copy.length(), UNORM_NFC, 0, reinterpret_cast<UChar*>(const_cast<DeprecatedChar*>(normalizedString.unicode())), copy.length(), &err);
        if (err == U_BUFFER_OVERFLOW_ERROR) {
            err = U_ZERO_ERROR;
            normalizedString.truncate(normalizedLength);
            normalizedLength = unorm_normalize(source, copy.length(), UNORM_NFC, 0, reinterpret_cast<UChar*>(const_cast<DeprecatedChar*>(normalizedString.unicode())), normalizedLength, &err);
        }
        
        source = reinterpret_cast<const UChar*>(normalizedString.unicode());
        sourceLimit = source + normalizedLength;
    }

    DeprecatedCString result(1); // for trailing zero

    if (allowEntities)
        ucnv_setFromUCallBack(m_converterICU, UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_XML_DEC, 0, 0, &err);
    else {
        ucnv_setSubstChars(m_converterICU, "?", 1, &err);
        ucnv_setFromUCallBack(m_converterICU, UCNV_FROM_U_CALLBACK_SUBSTITUTE, 0, 0, 0, &err);
    }

    ASSERT(U_SUCCESS(err));
    if (U_FAILURE(err))
        return DeprecatedCString();

    do {
        char* target = buffer;
        char* targetLimit = target + ConversionBufferSize;
        err = U_ZERO_ERROR;
        ucnv_fromUnicode(m_converterICU, &target, targetLimit, &source, sourceLimit, 0, true,  &err);
        int count = target - buffer;
        buffer[count] = 0;
        result.append(buffer);
    } while (err == U_BUFFER_OVERFLOW_ERROR);

    return result;
}
Beispiel #17
0
void SelectionController::debugRenderer(RenderObject *r, bool selected) const
{
    if (r->node()->isElementNode()) {
        Element *element = static_cast<Element *>(r->node());
        fprintf(stderr, "%s%s\n", selected ? "==> " : "    ", element->localName().deprecatedString().latin1());
    }
    else if (r->isText()) {
        RenderText *textRenderer = static_cast<RenderText *>(r);
        if (textRenderer->stringLength() == 0 || !textRenderer->firstTextBox()) {
            fprintf(stderr, "%s#text (empty)\n", selected ? "==> " : "    ");
            return;
        }
        
        static const int max = 36;
        DeprecatedString text = String(textRenderer->string()).deprecatedString();
        int textLength = text.length();
        if (selected) {
            int offset = 0;
            if (r->node() == m_sel.start().node())
                offset = m_sel.start().offset();
            else if (r->node() == m_sel.end().node())
                offset = m_sel.end().offset();
                
            int pos;
            InlineTextBox *box = textRenderer->findNextInlineTextBox(offset, pos);
            text = text.mid(box->m_start, box->m_len);
            
            DeprecatedString show;
            int mid = max / 2;
            int caret = 0;
            
            // text is shorter than max
            if (textLength < max) {
                show = text;
                caret = pos;
            }
            
            // too few characters to left
            else if (pos - mid < 0) {
                show = text.left(max - 3) + "...";
                caret = pos;
            }
            
            // enough characters on each side
            else if (pos - mid >= 0 && pos + mid <= textLength) {
                show = "..." + text.mid(pos - mid + 3, max - 6) + "...";
                caret = mid;
            }
            
            // too few characters on right
            else {
                show = "..." + text.right(max - 3);
                caret = pos - (textLength - show.length());
            }
            
            show.replace('\n', ' ');
            show.replace('\r', ' ');
            fprintf(stderr, "==> #text : \"%s\" at offset %d\n", show.latin1(), pos);
            fprintf(stderr, "           ");
            for (int i = 0; i < caret; i++)
                fprintf(stderr, " ");
            fprintf(stderr, "^\n");
        }
        else {
            if ((int)text.length() > max)
                text = text.left(max - 3) + "...";
            else
                text = text.left(max);
            fprintf(stderr, "    #text : \"%s\"\n", text.latin1());
        }
    }
}