source: webkit/trunk/JavaScriptCore/kjs/ustring.h@ 1192

Last change on this file since 1192 was 1024, checked in by darin, 23 years ago

Merged KDE 3.0 final code in and:

JavaScriptCore:

  • kjs/internal.cpp:
  • kjs/property_map.cpp:
  • kjs/ustring.h: Removed some unneeded <config.h> includes so we are more similar to the real KDE sources.

Merged changes from KDE 3.0 final and did some build fixes.

  • kjs/grammar.*: Regenerated.
  • kjs/*.lut.h: Regenerated.

WebCore:

  • src/kdelibs/khtml/rendering/render_text.cpp: (TextSlave::printDecoration): Remove some minor gratuitous diffs vs. KDE.
  • src/kdelibs/khtml/rendering/render_text.cpp: (TextSlave::printDecoration): Richard updated to reflect changes in KDE.
  • src/kdelibs/khtml/css/css_valueimpl.cpp: (FontFamilyValueImpl::FontFamilyValueImpl): Fix comment.
  • src/kdelibs/khtml/css/cssstyleselector.cpp: Remove some gratuitous diffs vs. KDE.
  • src/kdelibs/khtml/html/html_objectimpl.cpp: (HTMLEmbedElementImpl::parseAttribute): Remove unneeded copy from KWQ's early days.
  • src/kdelibs/khtml/html/html_tableimpl.cpp: (HTMLTableElementImpl::parseAttribute), (HTMLTablePartElementImpl::parseAttribute): Remove unneeded copy from KWQ's early days.
  • src/kdelibs/khtml/html/htmltokenizer.cpp: (HTMLTokenizer::processToken): Redo the APPLE_CHANGES ifdef here.
  • src/kdelibs/khtml/khtmlpart_p.h: Update to latest kde.
  • src/kdelibs/khtml/khtmlview.cpp: (KHTMLView::KHTMLView): Add ifdef APPLE_CHANGES. (KHTMLView::~KHTMLView): Add ifdef APPLE_CHANGES. (KHTMLView::print): Remove code left in here during merge process.
  • src/kwq/KWQKHTMLPart.mm: Remove unused setFontSizes(), fontSizes(), and resetFontSizes(). After the merge is landed, remove more.
  • src/libwebcore.exp: Export updateStyleSelector() for WebKit.

Fix text to it displays at the right font size.

  • src/kdelibs/khtml/css/cssstyleselector.cpp: (CSSStyleSelector::computeFontSizes): Apply the same SCREEN_RESOLUTION hack here that we do elsewhere.
  • src/kdelibs/khtml/rendering/font.cpp: (Font::width): Use kMin instead of max (oops). (Font::update): Turn off font database chicanery.
  • src/kwq/KWQKHTMLPart.mm: (KHTMLPart::zoomFactor): Use zoom factor 100, not 1.

More fixes so text displays (still at wrong font size).

  • src/kdelibs/khtml/rendering/font.cpp: (max): New helper. (Font::drawText): Simplified implementation for now. (Font::width): Simplified implementation for now.
  • src/kwq/KWQColorGroup.mm: Reinstated QCOLOR_GROUP_SIZE.
  • src/kwq/qt/qfontmetrics.h: Removed charWidth and changed _width to take QChar *.
  • src/kwq/KWQFontMetrics.mm: Removed charWidth and changed _width to take QChar *.

Merged changes from KDE 3.0 final. Other fixes to get things compiling.

  • src/kdelibs/khtml/css/css_valueimpl.cpp: (CSSStyleDeclarationImpl::setProperty): Fix unused variable.
  • src/kdelibs/khtml/khtmlview.cpp: (KHTMLView::contentsContextMenuEvent): Fix unused variable.
  • src/kdelibs/khtml/rendering/font.cpp: (Font::drawText), (Font::width), (Font::update): Disable special "nsbp" logic for now. We can reenable it if necessary.
  • src/kdelibs/khtml/rendering/render_replaced.cpp: Fix mismerge.
  • src/kdelibs/khtml/rendering/render_text.cpp: (RenderText::nodeAtPoint): Fix unused variable.
  • src/kwq/KWQApplication.mm: (QDesktopWidget::width), (QApplication::desktop): Fix mismerge.
  • src/kwq/KWQColorGroup.mm: Fix QCOLOR_GROUP_SIZE.
  • src/kwq/KWQFontMetrics.mm: (QFontMetrics::lineSpacing): New. (QFontMetrics::width): Remove unused optimization.
  • src/kwq/qt/qfontmetrics.h: Add lineSpacing().

Merged changes from previous merge pass.

2002-03-25 Darin Adler <Darin Adler>

Last bit of making stuff compile and link. Probably will drop the merge now
and take it up again when it's time to merge in KDE 3.0 final.

  • src/kwq/KWQEvent.mm: (QFocusEvent::reason): New.
  • src/kwq/KWQPainter.mm: (QPainter::drawText): New overload.

2002-03-25 Darin Adler <Darin Adler>

  • src/kdelibs/khtml/rendering/font.cpp: (Font::width): Make it call _width so we don't lose the optimization.
  • src/kwq/KWQApplication.mm: (QDesktopWidget::screenNumber): New. (QDesktopWidget::screenGeometry): New. (QApplication::style): New.
  • src/kwq/KWQColorGroup.mm: (QColorGroup::highlight): New. (QColorGroup::highlightedText): New.
  • src/kwq/KWQFont.mm: (QFont::setPixelSize): New.
  • src/kwq/KWQFontMetrics.mm: (QFontMetrics::charWidth): New.
  • src/kwq/KWQKGlobal.mm: (KGlobal::locale): Implement. (KLocale::KLocale): New. (KLocale::languageList): New.
  • src/kwq/KWQKHTMLPart.mm: (KHTMLPart::sheetUsed): New. (KHTMLPart::setSheetUsed): New. (KHTMLPart::zoomFactor): New.
  • src/kwq/KWQKHTMLSettings.mm: (KHTMLSettings::mediumFontSize): New.
  • src/kwq/KWQScrollView.mm: (QScrollView::childX): New. (QScrollView::childY): New.
  • src/kwq/qt/qapplication.h: style() returns a QStyle &.
  • src/kwq/qt/qpalette.h: Add Highlight and HighlightedText.

2002-03-24 Darin Adler <Darin Adler>

More compiling. Still won't link.

  • src/kdelibs/khtml/khtmlview.cpp: Disable printing and drag and drop code.
  • src/kdelibs/khtml/rendering/render_text.cpp: (TextSlave::printDecoration): Temporarily turn off our smarter underlining since it relies on access to the string, and TextSlave doesn't have that any more. (RenderText::nodeAtPoint): Get rid of a workaround we don't need any more for a bug that was fixed by KDE folks.
  • src/kwq/KWQApplication.mm: (QApplication::desktop): Make the desktop be a QDesktopWidget.
  • src/kwq/qt/qnamespace.h: Add MetaButton.
  • src/kwq/qt/qtooltip.h: Add a maybeTip virtual function member and a virtual destructor.

2002-03-24 Darin Adler <Darin Adler>

Some fixes to get more stuff to compile.

  • src/kdelibs/khtml/ecma/kjs_dom.cpp: (DOMDocument::getValueProperty): Don't try to look at the private m_bComplete to display "complete". Just do "loading" and "loaded".
  • src/kdelibs/khtml/khtmlpart_p.h: #ifdef this all out for APPLE_CHANGES.
  • src/kdelibs/khtml/rendering/font.cpp: (Font::update): Add an explicit cast to int to avoid float -> int warning.
  • src/kdelibs/khtml/rendering/render_table.cpp: (RenderTable::calcColMinMax): Add an explicit cast to int to avoid uint compared with int warning.
  • src/kdelibs/khtml/xml/dom_docimpl.cpp: (DocumentImpl::recalcStyleSelector): Use sheetUsed() and setSheetUsed() functions on KHTMLPart intead of getting at private fields the way the real KDE code does.
  • src/kwq/KWQKHTMLPart.h: Declare zoomFactor(), sheetUsed(), and setSheetUsed().
  • src/kwq/KWQStyle.h: Add PM_DefaultFramWidth as another metric.
  • src/kwq/kdecore/klocale.h: Add languageList().
  • src/kwq/khtml/khtml_settings.h: Add mediumFontSize().
  • src/kwq/qt/qapplication.h: Add style() and QDesktopWidget.
  • src/kwq/qt/qevent.h: Add reason().
  • src/kwq/qt/qfont.h: Add setPixelSize(int).
  • src/kwq/qt/qfontmetrics.h: Add charWidth() and _charWidth() functions.
  • src/kwq/qt/qpainter.h: Add drawText() overload with position parameter.
  • src/kwq/qt/qpalette.h: Add highlight() and highlightedText().
  • src/kwq/qt/qscrollview.h: Add childX() and childY().
  • src/kwq/KWQApplication.mm: Change KWQDesktopWidget to QDesktopWidget.

WebKit:

  • WebView.subproj/IFPreferences.h:
  • WebView.subproj/IFPreferences.mm: (+[IFPreferences load]): Remove the old WebKitFontSizes preference. (-[IFPreferences mediumFontSize]), (-[IFPreferences setMediumFontSize:]): New.
  • WebView.subproj/IFWebView.mm: (-[IFWebView reapplyStyles]): Call updateStyleSelector() instead of recalcStyle().

Merged changes from previous merge branch.

2002-03-25 Darin Adler <Darin Adler>

  • WebView.subproj/IFPreferences.mm: (+[IFPreferences load]): Add WebKitMediumFontSizePreferenceKey.

WebBrowser:

  • Preferences.subproj/TextPreferences.m: (-[TextPreferences defaultFontSize]), (-[TextPreferences setDefaultFontSize:]): Just get and set the new mediumFontSize preference rather than doing the whole fontSizes preference dance.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.4 KB
Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2000 Harri Porten ([email protected])
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 *
21 */
22
23#ifndef _KJS_USTRING_H_
24#define _KJS_USTRING_H_
25
26#ifdef APPLE_CHANGES
27#ifndef KWQ_UNSIGNED_TYPES_DEFINED
28#define KWQ_UNSIGNED_TYPES_DEFINED
29typedef unsigned char uchar;
30typedef unsigned short ushort;
31typedef unsigned uint;
32typedef unsigned long ulong;
33#endif
34#endif
35
36/**
37 * @internal
38 */
39namespace DOM {
40 class DOMString;
41};
42class KJScript;
43class QString;
44class QConstString;
45
46namespace KJS {
47
48 class UCharReference;
49 class UString;
50
51 /**
52 * @short Unicode character.
53 *
54 * UChar represents a 16 bit Unicode character. It's internal data
55 * representation is compatible to XChar2b and QChar. It's therefore
56 * possible to exchange data with X and Qt with shallow copies.
57 */
58 struct UChar {
59 /**
60 * Construct a character with value 0.
61 */
62 UChar();
63 /**
64 * Construct a character with the value denoted by the arguments.
65 * @param h higher byte
66 * @param l lower byte
67 */
68 UChar(unsigned char h , unsigned char l);
69 /**
70 * Construct a character with the given value.
71 * @param u 16 bit Unicode value
72 */
73 UChar(unsigned short u);
74 UChar(const UCharReference &c);
75 /**
76 * @return The higher byte of the character.
77 */
78 unsigned char high() const { return uc >> 8; }
79 /**
80 * @return The lower byte of the character.
81 */
82 unsigned char low() const { return uc & 0xFF; }
83 /**
84 * @return the 16 bit Unicode value of the character
85 */
86 unsigned short unicode() const { return uc; }
87 public:
88 /**
89 * @return The character converted to lower case.
90 */
91 UChar toLower() const;
92 /**
93 * @return The character converted to upper case.
94 */
95 UChar toUpper() const;
96 /**
97 * A static instance of UChar(0).
98 */
99 static UChar null;
100 private:
101 friend class UCharReference;
102 friend class UString;
103 friend bool operator==(const UChar &c1, const UChar &c2);
104 friend bool operator==(const UString& s1, const char *s2);
105 friend bool operator<(const UString& s1, const UString& s2);
106
107 unsigned short uc;
108 };
109
110 inline UChar::UChar() : uc(0) { }
111 inline UChar::UChar(unsigned char h , unsigned char l) : uc(h << 8 | l) { }
112 inline UChar::UChar(unsigned short u) : uc(u) { }
113
114 /**
115 * @short Dynamic reference to a string character.
116 *
117 * UCharReference is the dynamic counterpart of @ref UChar. It's used when
118 * characters retrieved via index from a @ref UString are used in an
119 * assignment expression (and therefore can't be treated as being const):
120 * <pre>
121 * UString s("hello world");
122 * s[0] = 'H';
123 * </pre>
124 *
125 * If that sounds confusing your best bet is to simply forget about the
126 * existance of this class and treat is as being identical to @ref UChar.
127 */
128 class UCharReference {
129 friend class UString;
130 UCharReference(UString *s, unsigned int off) : str(s), offset(off) { }
131 public:
132 /**
133 * Set the referenced character to c.
134 */
135 UCharReference& operator=(UChar c);
136 /**
137 * Same operator as above except the argument that it takes.
138 */
139 UCharReference& operator=(char c) { return operator=(UChar(c)); }
140 /**
141 * @return Unicode value.
142 */
143 unsigned short unicode() const { return ref().unicode(); }
144 /**
145 * @return Lower byte.
146 */
147 unsigned char low() const { return ref().uc & 0xFF; }
148 /**
149 * @return Higher byte.
150 */
151 unsigned char high() const { return ref().uc >> 8; }
152 /**
153 * @return Character converted to lower case.
154 */
155 UChar toLower() const { return ref().toLower(); }
156 /**
157 * @return Character converted to upper case.
158 */
159 UChar toUpper() const { return ref().toUpper(); }
160 private:
161 // not implemented, can only be constructed from UString
162 UCharReference();
163
164 UChar& ref() const;
165 UString *str;
166 int offset;
167 };
168
169 /**
170 * @short 8 bit char based string class
171 */
172 class CString {
173 public:
174 CString() : data(0L) { }
175 CString(const char *c);
176 CString(const CString &);
177
178 ~CString();
179
180 CString &append(const CString &);
181 CString &operator=(const char *c);
182 CString &operator=(const CString &);
183 CString &operator+=(const CString &);
184
185 int size() const;
186 const char *c_str() const { return data; }
187 private:
188 char *data;
189 };
190
191 /**
192 * @short Unicode string class
193 */
194 class UString {
195 friend bool operator==(const UString&, const UString&);
196 friend class UCharReference;
197 /**
198 * @internal
199 */
200 struct Rep {
201 friend class UString;
202 friend bool operator==(const UString&, const UString&);
203 static Rep *create(UChar *d, int l);
204 inline UChar *data() const { return dat; }
205 inline int size() const { return len; }
206
207 inline void ref() { rc++; }
208 inline int deref() { return --rc; }
209
210 UChar *dat;
211 int len;
212 int rc;
213 static Rep null;
214 };
215
216 public:
217 /**
218 * Constructs a null string.
219 */
220 UString();
221 /**
222 * Constructs a string from the single character c.
223 */
224 UString(char c);
225 /**
226 * Constructs a string from a classical zero determined char string.
227 */
228 UString(const char *c);
229 /**
230 * Constructs a string from an array of Unicode characters of the specified
231 * length.
232 */
233 UString(const UChar *c, int length);
234 /**
235 * If copy is false a shallow copy of the string will be created. That
236 * means that the data will NOT be copied and you'll have to guarantee that
237 * it doesn't get deleted during the lifetime of the UString object.
238 * Behaviour defaults to a deep copy if copy is true.
239 */
240 UString(UChar *c, int length, bool copy);
241 /**
242 * Copy constructor. Makes a shallow copy only.
243 */
244 UString(const UString &);
245 /**
246 * Convenience declaration only ! You'll be on your own to write the
247 * implementation for a construction from QString.
248 *
249 * Note: feel free to contact me if you want to see a dummy header for
250 * your favourite FooString class here !
251 */
252 UString(const QString &);
253 /**
254 * Convenience declaration only ! See @ref UString(const QString&).
255 */
256 UString(const DOM::DOMString &);
257 /**
258 * Destructor. If this handle was the only one holding a reference to the
259 * string the data will be freed.
260 */
261 ~UString();
262
263 /**
264 * Constructs a string from an int.
265 */
266 static UString from(int i);
267 /**
268 * Constructs a string from an unsigned int.
269 */
270 static UString from(unsigned int u);
271 /**
272 * Constructs a string from a double.
273 */
274 static UString from(double d);
275
276 /**
277 * Append another string.
278 */
279 UString &append(const UString &);
280
281 /**
282 * @return The string converted to the 8-bit string type @ref CString().
283 */
284 CString cstring() const;
285 /**
286 * Convert the Unicode string to plain ASCII chars chopping of any higher
287 * bytes. This method should only be used for *debugging* purposes as it
288 * is neither Unicode safe nor free from side effects. In order not to
289 * waste any memory the char buffer is static and *shared* by all UString
290 * instances.
291 */
292 char *ascii() const;
293 /**
294 * @see UString(const QString&).
295 */
296 DOM::DOMString string() const;
297 /**
298 * @see UString(const QString&).
299 */
300 QString qstring() const;
301 /**
302 * @see UString(const QString&).
303 */
304 QConstString qconststring() const;
305
306 /**
307 * Assignment operator.
308 */
309 UString &operator=(const char *c);
310 /**
311 * Assignment operator.
312 */
313 UString &operator=(const UString &);
314 /**
315 * Appends the specified string.
316 */
317 UString &operator+=(const UString &s);
318
319 /**
320 * @return A pointer to the internal Unicode data.
321 */
322 const UChar* data() const { return rep->data(); }
323 /**
324 * @return True if null.
325 */
326 bool isNull() const { return (rep == &Rep::null); }
327 /**
328 * @return True if null or zero length.
329 */
330 bool isEmpty() const { return (!rep->len); }
331 /**
332 * Use this if you want to make sure that this string is a plain ASCII
333 * string. For example, if you don't want to lose any information when
334 * using @ref cstring() or @ref ascii().
335 *
336 * @return True if the string doesn't contain any non-ASCII characters.
337 */
338 bool is8Bit() const;
339 /**
340 * @return The length of the string.
341 */
342 int size() const { return rep->size(); }
343 /**
344 * Const character at specified position.
345 */
346 UChar operator[](int pos) const;
347 /**
348 * Writable reference to character at specified position.
349 */
350 UCharReference operator[](int pos);
351
352 /**
353 * Attempts an conversion to a number. Apart from floating point numbers,
354 * the algorithm will recognize hexadecimal representations (as
355 * indicated by a 0x or 0X prefix) and +/- Infinity.
356 * Returns NaN if the conversion failed.
357 * @param tolerant if true, toDouble can tolerate garbage after the number.
358 */
359 double toDouble(bool tolerant=false) const;
360 /**
361 * Attempts an conversion to an unsigned long integer. ok will be set
362 * according to the success.
363 */
364 unsigned long toULong(bool *ok = 0L) const;
365 /**
366 * @return Position of first occurence of f starting at position pos.
367 * -1 if the search was not successful.
368 */
369 int find(const UString &f, int pos = 0) const;
370 /**
371 * @return Position of first occurence of f searching backwards from
372 * position pos.
373 * -1 if the search was not successful.
374 */
375 int rfind(const UString &f, int pos) const;
376 /**
377 * @return The sub string starting at position pos and length len.
378 */
379 UString substr(int pos = 0, int len = -1) const;
380 /**
381 * Static instance of a null string.
382 */
383 static UString null;
384 private:
385 void attach(Rep *r);
386 void detach();
387 void release();
388 Rep *rep;
389 };
390
391 inline bool operator==(const UChar &c1, const UChar &c2) {
392 return (c1.uc == c2.uc);
393 }
394 bool operator==(const UString& s1, const UString& s2);
395 inline bool operator!=(const UString& s1, const UString& s2) {
396 return !KJS::operator==(s1, s2);
397 }
398 bool operator<(const UString& s1, const UString& s2);
399 bool operator==(const UString& s1, const char *s2);
400 inline bool operator!=(const UString& s1, const char *s2) {
401 return !KJS::operator==(s1, s2);
402 }
403 inline bool operator==(const char *s1, const UString& s2) {
404 return operator==(s2, s1);
405 }
406 inline bool operator!=(const char *s1, const UString& s2) {
407 return !KJS::operator==(s1, s2);
408 }
409 bool operator==(const CString& s1, const CString& s2);
410 UString operator+(const UString& s1, const UString& s2);
411
412}; // namespace
413
414#endif
Note: See TracBrowser for help on using the repository browser.