WebCore/css/CSSHelper.cpp
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
       
     3  * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
       
     4  *
       
     5  * This library is free software; you can redistribute it and/or
       
     6  * modify it under the terms of the GNU Library General Public
       
     7  * License as published by the Free Software Foundation; either
       
     8  * version 2 of the License, or (at your option) any later version.
       
     9  *
       
    10  * This library is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    13  * Library General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU Library General Public License
       
    16  * along with this library; see the file COPYING.LIB.  If not, write to
       
    17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
       
    18  * Boston, MA 02110-1301, USA.
       
    19  *
       
    20  */
       
    21 
       
    22 #include "config.h"
       
    23 #include "CSSHelper.h"
       
    24 
       
    25 #include "PlatformString.h"
       
    26 #include <wtf/Vector.h>
       
    27 
       
    28 namespace WebCore {
       
    29 
       
    30 String deprecatedParseURL(const String& url)
       
    31 {
       
    32     StringImpl* i = url.impl();
       
    33     if (!i)
       
    34         return url;
       
    35 
       
    36     int length = i->length();
       
    37 
       
    38     int o = 0;
       
    39     int l = length;
       
    40 
       
    41     while (0 < l && (*i)[o] <= ' ') {
       
    42         ++o;
       
    43         --l;
       
    44     }
       
    45     while (l > 0 && (*i)[o + l - 1] <= ' ')
       
    46         --l;
       
    47 
       
    48     if (l >= 5
       
    49             && ((*i)[o] == 'u' || (*i)[o] == 'U')
       
    50             && ((*i)[o + 1] == 'r' || (*i)[o + 1] == 'R')
       
    51             && ((*i)[o + 2] == 'l' || (*i)[o + 2] == 'L')
       
    52             && (*i)[o + 3] == '('
       
    53             && (*i)[o + l - 1] == ')') {
       
    54         o += 4;
       
    55         l -= 5;
       
    56     }
       
    57 
       
    58     while (0 < l && (*i)[o] <= ' ') {
       
    59         ++o;
       
    60         --l;
       
    61     }
       
    62     while (l > 0 && (*i)[o + l - 1] <= ' ')
       
    63         --l;
       
    64 
       
    65     if (l >= 2 && (*i)[o] == (*i)[o + l - 1] && ((*i)[o] == '\'' || (*i)[o] == '\"')) {
       
    66         o++;
       
    67         l -= 2;
       
    68     }
       
    69 
       
    70     while (0 < l && (*i)[o] <= ' ') {
       
    71         ++o;
       
    72         --l;
       
    73     }
       
    74     while (l > 0 && (*i)[o + l - 1] <= ' ')
       
    75         --l;
       
    76 
       
    77     const UChar* characters = i->characters();
       
    78 
       
    79     // Optimize for the likely case there there is nothing to strip.
       
    80     if (l == length) {
       
    81         int k;
       
    82         // If the URL has any control characters in it, we have to strip them.
       
    83         // '\r' (ascii value 13) is the largest control character.
       
    84         for (k = 0; k < length; k++) {
       
    85             if (characters[k] <= '\r')
       
    86                 break;
       
    87         }
       
    88         if (k == length)
       
    89             return url;
       
    90     }
       
    91 
       
    92     Vector<UChar, 2048> buffer(l);
       
    93 
       
    94     int nl = 0;
       
    95     for (int k = o; k < o + l; k++) {
       
    96         UChar c = characters[k];
       
    97         if (c > '\r')
       
    98             buffer[nl++] = c;
       
    99     }
       
   100 
       
   101     return String(buffer.data(), nl);
       
   102 }
       
   103 
       
   104 } // namespace WebCore