media/omx-plugin/include/froyo/utils/String16.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/omx-plugin/include/froyo/utils/String16.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,267 @@
     1.4 +/*
     1.5 + * Copyright (C) 2005 The Android Open Source Project
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * Unless required by applicable law or agreed to in writing, software
    1.14 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.16 + * See the License for the specific language governing permissions and
    1.17 + * limitations under the License.
    1.18 + */
    1.19 +
    1.20 +#ifndef ANDROID_STRING16_H
    1.21 +#define ANDROID_STRING16_H
    1.22 +
    1.23 +#include <utils/Errors.h>
    1.24 +#include <utils/SharedBuffer.h>
    1.25 +
    1.26 +#include <stdint.h>
    1.27 +#include <sys/types.h>
    1.28 +
    1.29 +// ---------------------------------------------------------------------------
    1.30 +
    1.31 +extern "C" {
    1.32 +
    1.33 +#if !defined(__cplusplus) || __cplusplus == 199711L // C or C++98
    1.34 +typedef uint16_t char16_t;
    1.35 +#endif
    1.36 +
    1.37 +// Standard string functions on char16 strings.
    1.38 +int strcmp16(const char16_t *, const char16_t *);
    1.39 +int strncmp16(const char16_t *s1, const char16_t *s2, size_t n);
    1.40 +size_t strlen16(const char16_t *);
    1.41 +size_t strnlen16(const char16_t *, size_t);
    1.42 +char16_t *strcpy16(char16_t *, const char16_t *);
    1.43 +char16_t *strncpy16(char16_t *, const char16_t *, size_t);
    1.44 +
    1.45 +// Version of comparison that supports embedded nulls.
    1.46 +// This is different than strncmp() because we don't stop
    1.47 +// at a nul character and consider the strings to be different
    1.48 +// if the lengths are different (thus we need to supply the
    1.49 +// lengths of both strings).  This can also be used when
    1.50 +// your string is not nul-terminated as it will have the
    1.51 +// equivalent result as strcmp16 (unlike strncmp16).
    1.52 +int strzcmp16(const char16_t *s1, size_t n1, const char16_t *s2, size_t n2);
    1.53 +
    1.54 +// Version of strzcmp16 for comparing strings in different endianness.
    1.55 +int strzcmp16_h_n(const char16_t *s1H, size_t n1, const char16_t *s2N, size_t n2);
    1.56 +
    1.57 +// Convert UTF-8 to UTF-16 including surrogate pairs
    1.58 +void utf8_to_utf16(const uint8_t *src, size_t srcLen, char16_t* dst, const size_t dstLen);
    1.59 +
    1.60 +}
    1.61 +
    1.62 +// ---------------------------------------------------------------------------
    1.63 +
    1.64 +namespace android {
    1.65 +
    1.66 +// ---------------------------------------------------------------------------
    1.67 +
    1.68 +class String8;
    1.69 +class TextOutput;
    1.70 +
    1.71 +//! This is a string holding UTF-16 characters.
    1.72 +class String16
    1.73 +{
    1.74 +public:
    1.75 +                                String16();
    1.76 +                                String16(const String16& o);
    1.77 +                                String16(const String16& o,
    1.78 +                                         size_t len,
    1.79 +                                         size_t begin=0);
    1.80 +    explicit                    String16(const char16_t* o);
    1.81 +    explicit                    String16(const char16_t* o, size_t len);
    1.82 +    explicit                    String16(const String8& o);
    1.83 +    explicit                    String16(const char* o);
    1.84 +    explicit                    String16(const char* o, size_t len);
    1.85 +
    1.86 +                                ~String16();
    1.87 +    
    1.88 +    inline  const char16_t*     string() const;
    1.89 +    inline  size_t              size() const;
    1.90 +    
    1.91 +    inline  const SharedBuffer* sharedBuffer() const;
    1.92 +    
    1.93 +            void                setTo(const String16& other);
    1.94 +            status_t            setTo(const char16_t* other);
    1.95 +            status_t            setTo(const char16_t* other, size_t len);
    1.96 +            status_t            setTo(const String16& other,
    1.97 +                                      size_t len,
    1.98 +                                      size_t begin=0);
    1.99 +    
   1.100 +            status_t            append(const String16& other);
   1.101 +            status_t            append(const char16_t* other, size_t len);
   1.102 +            
   1.103 +    inline  String16&           operator=(const String16& other);
   1.104 +    
   1.105 +    inline  String16&           operator+=(const String16& other);
   1.106 +    inline  String16            operator+(const String16& other) const;
   1.107 +
   1.108 +            status_t            insert(size_t pos, const char16_t* chrs);
   1.109 +            status_t            insert(size_t pos,
   1.110 +                                       const char16_t* chrs, size_t len);
   1.111 +
   1.112 +            ssize_t             findFirst(char16_t c) const;
   1.113 +            ssize_t             findLast(char16_t c) const;
   1.114 +
   1.115 +            bool                startsWith(const String16& prefix) const;
   1.116 +            bool                startsWith(const char16_t* prefix) const;
   1.117 +            
   1.118 +            status_t            makeLower();
   1.119 +
   1.120 +            status_t            replaceAll(char16_t replaceThis,
   1.121 +                                           char16_t withThis);
   1.122 +
   1.123 +            status_t            remove(size_t len, size_t begin=0);
   1.124 +
   1.125 +    inline  int                 compare(const String16& other) const;
   1.126 +
   1.127 +    inline  bool                operator<(const String16& other) const;
   1.128 +    inline  bool                operator<=(const String16& other) const;
   1.129 +    inline  bool                operator==(const String16& other) const;
   1.130 +    inline  bool                operator!=(const String16& other) const;
   1.131 +    inline  bool                operator>=(const String16& other) const;
   1.132 +    inline  bool                operator>(const String16& other) const;
   1.133 +    
   1.134 +    inline  bool                operator<(const char16_t* other) const;
   1.135 +    inline  bool                operator<=(const char16_t* other) const;
   1.136 +    inline  bool                operator==(const char16_t* other) const;
   1.137 +    inline  bool                operator!=(const char16_t* other) const;
   1.138 +    inline  bool                operator>=(const char16_t* other) const;
   1.139 +    inline  bool                operator>(const char16_t* other) const;
   1.140 +    
   1.141 +    inline                      operator const char16_t*() const;
   1.142 +    
   1.143 +private:
   1.144 +            const char16_t*     mString;
   1.145 +};
   1.146 +
   1.147 +TextOutput& operator<<(TextOutput& to, const String16& val);
   1.148 +
   1.149 +// ---------------------------------------------------------------------------
   1.150 +// No user servicable parts below.
   1.151 +
   1.152 +inline int compare_type(const String16& lhs, const String16& rhs)
   1.153 +{
   1.154 +    return lhs.compare(rhs);
   1.155 +}
   1.156 +
   1.157 +inline int strictly_order_type(const String16& lhs, const String16& rhs)
   1.158 +{
   1.159 +    return compare_type(lhs, rhs) < 0;
   1.160 +}
   1.161 +
   1.162 +inline const char16_t* String16::string() const
   1.163 +{
   1.164 +    return mString;
   1.165 +}
   1.166 +
   1.167 +inline size_t String16::size() const
   1.168 +{
   1.169 +    return SharedBuffer::sizeFromData(mString)/sizeof(char16_t)-1;
   1.170 +}
   1.171 +
   1.172 +inline const SharedBuffer* String16::sharedBuffer() const
   1.173 +{
   1.174 +    return SharedBuffer::bufferFromData(mString);
   1.175 +}
   1.176 +
   1.177 +inline String16& String16::operator=(const String16& other)
   1.178 +{
   1.179 +    setTo(other);
   1.180 +    return *this;
   1.181 +}
   1.182 +
   1.183 +inline String16& String16::operator+=(const String16& other)
   1.184 +{
   1.185 +    append(other);
   1.186 +    return *this;
   1.187 +}
   1.188 +
   1.189 +inline String16 String16::operator+(const String16& other) const
   1.190 +{
   1.191 +    String16 tmp;
   1.192 +    tmp += other;
   1.193 +    return tmp;
   1.194 +}
   1.195 +
   1.196 +inline int String16::compare(const String16& other) const
   1.197 +{
   1.198 +    return strzcmp16(mString, size(), other.mString, other.size());
   1.199 +}
   1.200 +
   1.201 +inline bool String16::operator<(const String16& other) const
   1.202 +{
   1.203 +    return strzcmp16(mString, size(), other.mString, other.size()) < 0;
   1.204 +}
   1.205 +
   1.206 +inline bool String16::operator<=(const String16& other) const
   1.207 +{
   1.208 +    return strzcmp16(mString, size(), other.mString, other.size()) <= 0;
   1.209 +}
   1.210 +
   1.211 +inline bool String16::operator==(const String16& other) const
   1.212 +{
   1.213 +    return strzcmp16(mString, size(), other.mString, other.size()) == 0;
   1.214 +}
   1.215 +
   1.216 +inline bool String16::operator!=(const String16& other) const
   1.217 +{
   1.218 +    return strzcmp16(mString, size(), other.mString, other.size()) != 0;
   1.219 +}
   1.220 +
   1.221 +inline bool String16::operator>=(const String16& other) const
   1.222 +{
   1.223 +    return strzcmp16(mString, size(), other.mString, other.size()) >= 0;
   1.224 +}
   1.225 +
   1.226 +inline bool String16::operator>(const String16& other) const
   1.227 +{
   1.228 +    return strzcmp16(mString, size(), other.mString, other.size()) > 0;
   1.229 +}
   1.230 +
   1.231 +inline bool String16::operator<(const char16_t* other) const
   1.232 +{
   1.233 +    return strcmp16(mString, other) < 0;
   1.234 +}
   1.235 +
   1.236 +inline bool String16::operator<=(const char16_t* other) const
   1.237 +{
   1.238 +    return strcmp16(mString, other) <= 0;
   1.239 +}
   1.240 +
   1.241 +inline bool String16::operator==(const char16_t* other) const
   1.242 +{
   1.243 +    return strcmp16(mString, other) == 0;
   1.244 +}
   1.245 +
   1.246 +inline bool String16::operator!=(const char16_t* other) const
   1.247 +{
   1.248 +    return strcmp16(mString, other) != 0;
   1.249 +}
   1.250 +
   1.251 +inline bool String16::operator>=(const char16_t* other) const
   1.252 +{
   1.253 +    return strcmp16(mString, other) >= 0;
   1.254 +}
   1.255 +
   1.256 +inline bool String16::operator>(const char16_t* other) const
   1.257 +{
   1.258 +    return strcmp16(mString, other) > 0;
   1.259 +}
   1.260 +
   1.261 +inline String16::operator const char16_t*() const
   1.262 +{
   1.263 +    return mString;
   1.264 +}
   1.265 +
   1.266 +}; // namespace android
   1.267 +
   1.268 +// ---------------------------------------------------------------------------
   1.269 +
   1.270 +#endif // ANDROID_STRING16_H

mercurial