WebCore/bindings/cpp/WebDOMString.h
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
       
     3  * Copyright (C) 2009 Google 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 #ifndef WebDOMString_h
       
    22 #define WebDOMString_h
       
    23 
       
    24 #include <WebDOMCString.h>
       
    25 
       
    26 namespace WebCore {
       
    27 class String;
       
    28 class AtomicString;
       
    29 }
       
    30 
       
    31 class WebDOMStringPrivate;
       
    32 
       
    33 // A UTF-16 string container.  It is inexpensive to copy a WebDOMString
       
    34 // object.
       
    35 //
       
    36 // WARNING: It is not safe to pass a WebDOMString across threads!!!
       
    37 //
       
    38 class WebDOMString {
       
    39 public:
       
    40     ~WebDOMString() { reset(); }
       
    41 
       
    42     WebDOMString() : m_private(0) { }
       
    43 
       
    44     WebDOMString(const WebUChar* data, size_t len) : m_private(0)
       
    45     {
       
    46         assign(data, len);
       
    47     }
       
    48 
       
    49     WebDOMString(const WebDOMString& s) : m_private(0) { assign(s); }
       
    50 
       
    51     WebDOMString& operator=(const WebDOMString& s)
       
    52     {
       
    53         assign(s);
       
    54         return *this;
       
    55     }
       
    56 
       
    57     void reset();
       
    58     void assign(const WebDOMString&);
       
    59     void assign(const WebUChar* data, size_t len);
       
    60 
       
    61     size_t length() const;
       
    62     const WebUChar* data() const;
       
    63 
       
    64     bool isEmpty() const { return !length(); }
       
    65     bool isNull() const { return !m_private; }
       
    66 
       
    67     WebDOMCString utf8() const;
       
    68 
       
    69     static WebDOMString fromUTF8(const char* data, size_t length);
       
    70     static WebDOMString fromUTF8(const char* data);
       
    71 
       
    72     template <int N> WebDOMString(const char (&data)[N])
       
    73         : m_private(0)
       
    74     {
       
    75         assign(fromUTF8(data, N - 1));
       
    76     }
       
    77 
       
    78     template <int N> WebDOMString& operator=(const char (&data)[N])
       
    79     {
       
    80         assign(fromUTF8(data, N - 1));
       
    81         return *this;
       
    82     }
       
    83 
       
    84     WebDOMString(const WebCore::String&);
       
    85     WebDOMString& operator=(const WebCore::String&);
       
    86     operator WebCore::String() const;
       
    87 
       
    88     WebDOMString(const WebCore::AtomicString&);
       
    89     WebDOMString& operator=(const WebCore::AtomicString&);
       
    90     operator WebCore::AtomicString() const;
       
    91 
       
    92     bool equals(const char* string) const;
       
    93 
       
    94 private:
       
    95     void assign(WebDOMStringPrivate*);
       
    96     WebDOMStringPrivate* m_private;
       
    97 };
       
    98 
       
    99 #endif