Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: webkit/port/platform/BString.cpp

Issue 7419: Move many files that were suffixed Win.cpp to Chromium.cpp, and place them in... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/port/platform/BString.h ('k') | webkit/port/platform/COMPtr.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "config.h"
27 #include "BString.h"
28
29 #include "AtomicString.h"
30 #include "KURL.h"
31 #include "PlatformString.h"
32 #include <comdef.h>
33 #include <tchar.h>
34 #include <windows.h>
35
36 #if PLATFORM(CF)
37 #include <CoreFoundation/CoreFoundation.h>
38 #endif
39
40 using namespace KJS;
41
42 namespace WebCore {
43
44 BString::BString()
45 : m_bstr(0)
46 {
47 }
48
49 BString::BString(const wchar_t* characters)
50 {
51 if (!characters)
52 m_bstr = 0;
53 else
54 m_bstr = SysAllocString(characters);
55 }
56
57 BString::BString(const wchar_t* characters, size_t length)
58 {
59 if (!characters)
60 m_bstr = 0;
61 else
62 m_bstr = SysAllocStringLen(characters, length);
63 }
64
65 BString::BString(const String& s)
66 {
67 if (s.isNull())
68 m_bstr = 0;
69 else
70 m_bstr = SysAllocStringLen(s.characters(), s.length());
71 }
72
73 BString::BString(const KURL& url)
74 {
75 if (url.isNull())
76 m_bstr = 0;
77 else
78 m_bstr = SysAllocStringLen(url.string().characters(), url.string().lengt h());
79 }
80
81 BString::BString(const AtomicString& s)
82 {
83 if (s.isNull())
84 m_bstr = 0;
85 else
86 m_bstr = SysAllocStringLen(s.characters(), s.length());
87 }
88
89 #if PLATFORM(CF)
90 BString::BString(CFStringRef cfstr)
91 : m_bstr(0)
92 {
93 if (!cfstr)
94 return;
95
96 const UniChar* uniChars = CFStringGetCharactersPtr(cfstr);
97 if (uniChars) {
98 m_bstr = SysAllocStringLen((LPCTSTR)uniChars, CFStringGetLength(cfstr));
99 return;
100 }
101
102 CFIndex length = CFStringGetLength(cfstr);
103 m_bstr = SysAllocStringLen(0, length);
104 CFStringGetCharacters(cfstr, CFRangeMake(0, length), (UniChar*)m_bstr);
105 m_bstr[length] = 0;
106 }
107 #endif
108
109 BString::~BString()
110 {
111 SysFreeString(m_bstr);
112 }
113
114 BString::BString(const BString& other)
115 {
116 if (!other.m_bstr)
117 m_bstr = 0;
118 else
119 m_bstr = SysAllocString(other.m_bstr);
120 }
121
122 void BString::adoptBSTR(BSTR bstr)
123 {
124 if (m_bstr)
125 SysFreeString(m_bstr);
126 m_bstr = bstr;
127 }
128
129 BString& BString::operator=(const BString& other)
130 {
131 if (this != &other)
132 *this = other.m_bstr;
133 return *this;
134 }
135
136 BString& BString::operator=(const BSTR& other)
137 {
138 if (other != m_bstr) {
139 SysFreeString(m_bstr);
140 m_bstr = other ? SysAllocString(other) : 0;
141 }
142
143 return *this;
144 }
145
146 bool operator ==(const BString& a, const BString& b)
147 {
148 if (SysStringLen((BSTR)a) != SysStringLen((BSTR)b))
149 return false;
150 if (!(BSTR)a && !(BSTR)b)
151 return true;
152 if (!(BSTR)a || !(BSTR)b)
153 return false;
154 return !_tcscmp((BSTR)a, (BSTR)b);
155 }
156
157 bool operator !=(const BString& a, const BString& b)
158 {
159 return !(a==b);
160 }
161
162 bool operator ==(const BString& a, BSTR b)
163 {
164 if (SysStringLen((BSTR)a) != SysStringLen(b))
165 return false;
166 if (!(BSTR)a && !b)
167 return true;
168 if (!(BSTR)a || !b)
169 return false;
170 return !_tcscmp((BSTR)a, b);
171 }
172
173 bool operator !=(const BString& a, BSTR b)
174 {
175 return !(a==b);
176 }
177
178 bool operator ==(BSTR a, const BString& b)
179 {
180 if (SysStringLen(a) != SysStringLen((BSTR)b))
181 return false;
182 if (!a && !(BSTR)b)
183 return true;
184 if (!a || !(BSTR)b)
185 return false;
186 return !_tcscmp(a, (BSTR)b);
187 }
188
189 bool operator !=(BSTR a, const BString& b)
190 {
191 return !(a==b);
192 }
193
194 }
OLDNEW
« no previous file with comments | « webkit/port/platform/BString.h ('k') | webkit/port/platform/COMPtr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698