- test for http://bugzilla.opendarwin.org/show_bug.cgi?id=6310
text-transform: uppercase/lowercase don't handle cases one character becomes two
* fast/css/case-transform.html: Added.
* fast/css/case-transform-expected.txt: Added.
WebCore:
Rubber stamped by Hyatt.
- http://bugzilla.opendarwin.org/show_bug.cgi?id=8782
use ICU and UChar more, QChar less
- fix http://bugzilla.opendarwin.org/show_bug.cgi?id=6310
text-transform: uppercase/lowercase don't handle cases one character becomes two
Test: fast/css/case-transform.html
By using ICU more, this fixes some bugs in a few places.
* bindings/js/JSXMLSerializer.cpp:
* css/css_valueimpl.h:
* kwq/KWQTextStream.cpp:
* loader/CachedObject.h:
* platform/Color.cpp:
Add includes of DeprecatedString.h as needed, now that StringImpl.h no longer
includes it.
* bindings/js/kjs_css.cpp: (KJS::cssPropertyName):
Eliminate use of QChar::latin1() in a case where it's not helpful.
* bindings/js/kjs_proxy.cpp: (WebCore::KJSProxy::evaluate):
Use characters() function instead of the old unicode() function.
* bindings/js/kjs_window.cpp: (KJS::isSeparator):
Use UChar instead of QChar.
* bindings/objc/DOMInternal.mm:
(StringImpl::operator NSString*): Remove typecast that's no longer needed.
(String::String): Ditto. Also use Vector for local buffer to make code read simpler.
* bridge/mac/FrameMac.mm:
(WebCore::selectorForKeyEvent): Remove call to unicode() function, no longer needed.
(WebCore::FrameMac::setTitle): Remove QChar cast, no longer needed.
(WebCore::FrameMac::setStatusBarText): Ditto.
(WebCore::FrameMac::advanceToNextMisspelling): Use UChar instead of QChar.
(WebCore::FrameMac::runJavaScriptAlert): Remove QChar cast, no longer needed.
(WebCore::FrameMac::runJavaScriptConfirm): Ditto.
(WebCore::FrameMac::runJavaScriptPrompt): Ditto.
(WebCore::FrameMac::attributedString): Replaces calls of QChar::direction() with
calls to u_charDirection and use ICU constants instead of QChar ones.
(WebCore::FrameMac::markMisspellings): Remove QChar cast, no longer needed. Added a
QChar cast so we can call isSpace -- slated to be removed later.
(WebCore::FrameMac::shouldClose): Remove QChar cast, no longer needed.
* bridge/mac/WebCoreFrameBridge.mm:
(-[WebCoreFrameBridge selectedString]): Remove QChar cast, no longer needed.
(-[WebCoreFrameBridge stringForRange:]): Ditto.
* css/CSSGrammar.y: Update for field name change from string to characters.
Use UChar instead of unsigned short.
* css/css_valueimpl.cpp:
(WebCore::propertyID): Use UChar instead of unsigned short and get rid of call to
unicode() function, no longer needed.
(WebCore::quoteStringIfNeeded): Use strings when building up a resulting string,
instead of depending on the feature where you can append characters to a string.
* css/csshelper.cpp: (WebCore::parseURL): Remove calls to unicode() function and
rewrite to obviate the need to call lower() just to check for a few constant
character values. Also remove a now-unneeded type cast.
* css/cssparser.h: Changed ParseString field to use UChar and to be named characters
instead of string. Changed many other fields to be UChar instead of unsigned short.
(WebCore::domString): Update for that.
(WebCore::atomicString): Ditto.
* css/cssparser.cpp:
(WebCore::ParseString::lower): Use u_tolower instead of QChar::lower(). Also change
name to characters from string.
(WebCore::CSSParser::setupParser): Use UChar instead of unsigned short.
(WebCore::CSSParser::lex): Ditto. Also update for characters name change.
(WebCore::CSSParser::text): Use UChar instead of unsigned short. Also tweak some
of the code a little bit to handle a couple of overflow cases better and reduce
type casting.
(WebCore::deprecatedString): Moved here so we don't have to include DeprecatedString.h
in the header file.
* css/cssstyleselector.cpp: (WebCore::checkPseudoState): Added a type cast since this
code now bridges the world between modern code and QChar/DeprecatedString.
* dom/CharacterData.cpp: (WebCore::CharacterData::CharacterData): Changed QChar to UChar.
* dom/Document.h:
* dom/Document.cpp:
(WebCore::Document::isValidName): Updated for name change from unicode to characters.
(WebCore::Document::parseQualifiedName): Ditto.
(WebCore::Document::backslashAsCurrencySymbol): Changed return type to UChar.
* dom/NamedMappedAttrMap.cpp:
(WebCore::isClassWhitespace): Changed parameter to UChar from QChar.
(WebCore::NamedMappedAttrMap::parseClassAttribute): Changed from UChar to QChar and
from unicode to characters.
* dom/Position.cpp:
(WebCore::Position::leadingWhitespacePosition): Changed from QChar to UChar.
(WebCore::Position::trailingWhitespacePosition): Ditto.
* dom/StyledElement.cpp:
(WebCore::isClassWhitespace): Changed from QChar to UChar.
(WebCore::StyledElement::addCSSLength): Changed from QChar to UChar, and remove one
case where latin1() was used and was not helpful.
(WebCore::StyledElement::addCSSColor): Removed unicode() function call, no longer needed.
* dom/dom2_eventsimpl.cpp: (WebCore::KeyboardEvent::charCode):
* html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::constrainValue):
Removed unicode() function call, no longer needed.
* dom/xml_tokenizer.h: Removed default parameter for xmlDocPtrForString so we don't have
to include the DeprecatedString.h header in this file (and since no one uses it).
* editing/HTMLInterchange.cpp: (convertHTMLTextToInterchangeFormat): Added a couple calls
to the unicode() function to bridge the gap from QChar/DeprecatedString back to modern
code.
* editing/InsertTextCommand.cpp: Removed unused function.
* editing/TextIterator.h: Changed from QChar to UChar.
* editing/TextIterator.cpp:
(WebCore::TextIterator::TextIterator): Initialize m_lastCharacter since it's now a UChar
(which is just a typedef) rather than a QChar (which was a class with a default value of 0).
(WebCore::TextIterator::handleTextNode): Updated to use characters() instead of unicode().
(WebCore::TextIterator::handleTextBox): Removed unicode() call since it's now a UChar instead
of a QChar.
(WebCore::TextIterator::emitCharacter): More of the same.
(WebCore::SimplifiedBackwardsTextIterator::handleTextNode): Ditto.
(WebCore::SimplifiedBackwardsTextIterator::emitCharacter): Ditto.
(WebCore::CharacterIterator::string): Ditto.
(WebCore::WordAwareIterator::advance): Ditto.
(WebCore::WordAwareIterator::length): Ditto.
(WebCore::WordAwareIterator::characters): Ditto.
(WebCore::CircularSearchBuffer::CircularSearchBuffer): Changed to use UChar
instead of QChar, but also to use foldCase() instead of lower(), because
we want case folding here, not lowercasing.
(WebCore::CircularSearchBuffer::append): Ditto, with u_foldCase.
(WebCore::CircularSearchBuffer::isMatch): Ditto.
(WebCore::plainText): Added type cast since this bridges the gap from the modern stuff
to QChar/DeprecatedString.
* editing/VisiblePosition.h: Changed from QChar to UChar.
* editing/VisiblePosition.cpp: (WebCore::VisiblePosition::characterAfter): Ditto.
* editing/markup.cpp: (WebCore::escapeTextForMarkup): Changed code that used latin1()
for no good reason to use unicode() instead.
* html/HTMLTokenizer.h: Changed from QChar to UChar.
* html/HTMLTokenizer.cpp: Changed from QChar to UChar, including removing the
KHTML_ALLOC_QCHAR_VEC and KHTML_DELETE_QCHAR_VEC macros, which weren't being
used consistently anyway.
(WebCore::fixUpChar): More of the same.
(WebCore::tagMatch): Ditto.
(WebCore::HTMLTokenizer::reset): Ditto.
(WebCore::HTMLTokenizer::begin): Ditto. Also corrected anomaly where buffer
size was not the same as the size value -- this was only true in the initial
allocation, so I believe there was no value in it.
(WebCore::HTMLTokenizer::parseSpecial): Ditto. Also removed a use of latin1()
that was unnnecessary extra work.
(WebCore::HTMLTokenizer::scriptHandler): More of the same.
(WebCore::HTMLTokenizer::parseComment): Ditto.
(WebCore::HTMLTokenizer::parseServer): Ditto.
(WebCore::HTMLTokenizer::parseProcessingInstruction): Ditto. Another unnecessary
use of latin1() removed.
(WebCore::HTMLTokenizer::parseText): Ditto.
(WebCore::HTMLTokenizer::parseEntity): Ditto. Changed hex-parsing code to handle
uppercase hex a more-efficient way than calling QChar::lower() on each character.
Also changed surrogate code logic to fix a couple things -- reject character codes
> 0x10FFFF as it should and use U16_LEAD and U16_TRAIL instead of writing our
own versions of these.
(WebCore::HTMLTokenizer::parseTag): Ditto.
(WebCore::HTMLTokenizer::write): Ditto.
(WebCore::HTMLTokenizer::end): Ditto.
(WebCore::HTMLTokenizer::finish): Ditto.
(WebCore::HTMLTokenizer::enlargeBuffer): Ditto.
(WebCore::HTMLTokenizer::enlargeScriptBuffer): Ditto.
(WebCore::HTMLTokenizer::notifyFinished):
(WebCore::decodeNamedEntity): Ditto.
* html/html_inlineimpl.cpp: (WebCore::parseFontSizeNumber): Changed from QChar
to UChar, including using u_isdigit and u_charDigitValue instead of QChar::isNumber
and QChar::digitValue. Also removed unneeded range checking that's already done
by WebCore::String.
* kwq/KWQLoader.mm: (KWQIsResponseURLEqualToURL): Rewrote to use Vector and UChar,
removing all the type casts and making the whole function much shorter.
* kwq/WebCoreAXObject.mm:
(AXAttributedStringAppendText): Use UChar instead of QChar.
(-[WebCoreAXObject doAXAttributedStringForTextMarkerRange:]): More of the same.
* loader/Cache.h: Remove unnecessary default parameters, preventing the need to
include the DeprecatedString.h header in this header. Cleaned up the header
structure a bit, removing some obsolete and redundant comments and fixing typos.
* loader/Cache.cpp: Removed unused preload functions.
* page/Frame.h:
* page/Frame.cpp:
(WebCore::UserStyleSheetLoader::UserStyleSheetLoader): Added explicit arguments.
This was the only caller anywhere that took advantage of the default parameter
values in one of the Cache class request functions.
(WebCore::Frame::backslashAsCurrencySymbol): Changed QChar to UChar.
* platform/AtomicString.h: Changed QChar to UChar. Removed constructor that makes
an AtomicString from a single character. Renamed unicode() function to characters().
Renamed KHTML_ATOMICSTRING_HIDE_GLOBALS to ATOMICSTRING_HIDE_GLOBALS.
* platform/AtomicString.cpp:
(WebCore::CStringTranslator::equal): Changed QChar to UChar.
(WebCore::operator==): Changed unicode() to characters().
(WebCore::UCharBufferTranslator::hash): More of the same.
(WebCore::UCharBufferTranslator::equal): Ditto.
(WebCore::UCharBufferTranslator::translate): Ditto.
(WebCore::AtomicString::add): Ditto.
(WebCore::AtomicString::operator Identifier): Ditto.
(WebCore::AtomicString::operator UString): Ditto.
(WebCore::AtomicString::AtomicString): Moved here so we don't need DeprecatedString.h
in the header.
(WebCore::AtomicString::deprecatedString): Ditto.
* platform/DeprecatedString.h: Removed QChar::Direction enum and all the DirXXX values,
isDigit, isLetter, isNumber, isLetterOrNumber, isPunct, digitValue, and direction functions.
(QChar::isSpace): Changed to use u_charDirection instead of QChar::direction.
* platform/Font.h: (WebCore::Font::width): Changed QChar to UChar.
* platform/Font.cpp: (WebCore::Font::width): Ditto.
* platform/GraphicsContext.h:
* platform/GraphicsContext.cpp:
(WebCore::GraphicsContext::drawText): Changed QChar to UChar. Removed horizontalAlignment
parameter from simplified string drawing entry point, since it's not used.
(WebCore::GraphicsContext::drawHighlightForText): Changed QChar to UChar.
* platform/PlatformString.h: Changed QChar to UChar. Removed constructor that makes
a String from a single character. Renamed unicode() function to characters(). Added
an append function and changed += operator to just call that. Added a foldCase() function.
Removed the concatenation operators that add individual strings before or after.
* platform/String.cpp:
(WebCore::String::String): Changed QChar to UChar.
(WebCore::String::append): Renamed from operator+= and removed the return value.
(WebCore::String::operator[]): Changed QChar to UChar.
(WebCore::String::foldCase): Added.
(WebCore::String::percentage): More of the same.
(WebCore::String::characters): Renamed from unicode().
(WebCore::String::deprecatedString): More of the same.
(WebCore::String::sprintf): Fixed mistakes in the comments.
(WebCore::String::isEmpty): Tweaked a bit.
(WebCore::operator==): More of the same.
(WebCore::String::operator Identifier): Ditto.
(WebCore::String::operator UString): Ditto.
* platform/SegmentedString.h: Changed from QChar to UChar. Had to initialize
data members that are now UChar.
* platform/SegmentedString.cpp:
(WebCore::SegmentedString::length): Updated for change from QChar to UChar.
(WebCore::SegmentedString::append): Ditto.
(WebCore::SegmentedString::prepend): Ditto.
(WebCore::SegmentedString::toString): Ditto.
* platform/StringHash.h: Updated to use UChar instead of QChar and for name changes.
Also changed to use case folding intead of lowercasing for case insensitive hashing.
* platform/StringImpl.h:
* platform/StringImpl.cpp:
(WebCore::newUCharVector): Changed to UChar from QChar.
(WebCore::deleteUCharVector): Ditto.
(WebCore::StringImpl::StringImpl): Ditto.
(WebCore::StringImpl::init): Ditto. Also renamed from initWithChar and initWithQChar.
(WebCore::StringImpl::~StringImpl): Ditto.
(WebCore::StringImpl::append): Ditto.
(WebCore::StringImpl::insert): Ditto.
(WebCore::StringImpl::truncate): Ditto.
(WebCore::StringImpl::remove): Ditto.
(WebCore::StringImpl::split): Ditto.
(WebCore::StringImpl::containsOnlyWhitespace): Ditto. Also added comment because this
function seems a little broken.
(WebCore::parseLength): More of the same.
(WebCore::StringImpl::toCoordsArray): Ditto.
(WebCore::StringImpl::toLengthArray): Ditto.
(WebCore::StringImpl::isLower): Ditto.
(WebCore::StringImpl::lower): Rewrote to use u_strToLower.
(WebCore::StringImpl::upper): Rewrote to use u_strToUpper.
(WebCore::StringImpl::foldCase): Added. Uses u_strFoldCase.
(WebCore::getWordBreakIterator): Changed to use U_FAILURE instead of accepting only
U_ZERO_ERROR as a success code.
(WebCore::StringImpl::capitalize): More QChar to UChar changes.
(WebCore::StringImpl::toInt): Ditto.
(WebCore::equal): Changed from QChar to UChar and was careful to preserve the old
semantics where "high ASCII" is treated as U+0080-U+00FF even though I don't know
if this feature is important.
(WebCore::equalIgnoringCase): Ditto, but used case folding instead of lowercasing
by using the u_foldCase and u_memcasecmp functions. Also renamed from
equalCaseInsensitive for more-consistent naming.
(WebCore::StringImpl::find): Ditto. Use case folding for the case insensitive branch.
(WebCore::StringImpl::replace): More of the same.
(WebCore::StringImpl::computeHash): Ditto.
(WebCore::StringImpl::ascii): Ditto.
* platform/TextBoundaries.h: Changed from QChar to UChar.
* platform/mac/TextBoundaries.mm:
(WebCore::findWordBoundary): Made the change to UChar and removed some type casts.
(WebCore::findNextWordFromIndex): Ditto.
(WebCore::findSentenceBoundary): Ditto.
(WebCore::findNextSentenceFromIndex): Ditto.
* platform/TextEncoding.h:
* platform/TextEncoding.cpp:
(WebCore::TextEncoding::backslashAsCurrencySymbol): Changed from QChar to UChar.
(WebCore::TextEncoding::fromUnicode): More of the same.
* platform/mac/TextEncodingMac.cpp: (WebCore::TextEncoding::fromUnicode): More
of the same.
* platform/mac/FontFamilyMac.mm: (WebCore::FontFamily::getNSFamily): Removed a
now-unneeded type cast.
* platform/mac/FontMac.mm:
(WebCore::Font::selectionRectForText):
(WebCore::Font::drawText):
(WebCore::Font::drawHighlightForText):
(WebCore::Font::floatWidth):
(WebCore::Font::checkSelectionPoint):
Changed QChar to UChar and removed some now-unneeded type casts.
* editing/RebalanceWhitespaceCommand.cpp: (WebCore::isWhitespace):
* editing/ReplaceSelectionCommand.cpp: (WebCore::ReplaceSelectionCommand::doApply):
* editing/visible_units.cpp:
(WebCore::previousBoundary):
(WebCore::nextBoundary):
(WebCore::startWordBoundary):
(WebCore::endWordBoundary):
(WebCore::previousWordPositionBoundary):
(WebCore::nextWordPositionBoundary):
(WebCore::startSentenceBoundary):
(WebCore::endSentenceBoundary):
(WebCore::previousSentencePositionBoundary):
(WebCore::nextSentencePositionBoundary):
(WebCore::startOfParagraph):
(WebCore::endOfParagraph):
* html/HTMLParser.cpp: (WebCore::HTMLParser::handleError):
* rendering/InlineTextBox.cpp:
(WebCore::InlineTextBox::selectionRect):
(WebCore::InlineTextBox::paint):
(WebCore::InlineTextBox::paintSelection):
(WebCore::InlineTextBox::paintMarkedTextBackground):
(WebCore::InlineTextBox::paintTextMatchMarker):
(WebCore::InlineTextBox::offsetForPosition):
(WebCore::InlineTextBox::positionForOffset):
* rendering/RenderBlock.cpp:
(WebCore::stripTrailingSpace):
(WebCore::RenderBlock::updateFirstLetter):
* rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::layoutVerticalBox):
* rendering/RenderObject.h:
* rendering/RenderObject.cpp:
(WebCore::RenderObject::backslashAsCurrencySymbol):
* rendering/RenderTreeAsText.cpp: (quoteAndEscapeNonPrintables):
* rendering/break_lines.cpp: (WebCore::nextBreakablePosition):
* rendering/break_lines.h: (WebCore::isBreakable):
* rendering/render_style.h: (WebCore::RenderStyle::isCollapsibleWhiteSpace):
* xml/XSLStyleSheet.cpp: (WebCore::XSLStyleSheet::parseString):
* xml/xmlhttprequest.cpp:
(WebCore::getMIMEType):
(WebCore::getCharset):
Changed QChar to UChar.
* rendering/RenderImage.cpp:
(WebCore::RenderImage::imageChanged): Changed QChar to UChar.
(WebCore::RenderImage::paint): Changed callers of drawText to no-longer pass 0
for the horizontal alignment, since I removed that parameters.
* rendering/RenderText.h: Changed QChar to UChar.
* rendering/RenderText.cpp:
(WebCore::characterBreakIterator): Update for name change.
(WebCore::RenderText::RenderText): Ditto.
(WebCore::RenderText::allAscii): Remove uneeded unicode() and allow the value
U+007F to count as ASCII.
(WebCore::RenderText::cacheWidths): Changed QChar to UChar.
(WebCore::RenderText::widthFromCache): Changed code that deals with direction to
use the ICU direction calls.
(WebCore::RenderText::trimmedMinMaxWidth): Changed QChar to UChar.
(WebCore::RenderText::calcMinMaxWidth): Ditto.
(WebCore::RenderText::containsOnlyWhitespace): Ditto.
(WebCore::RenderText::setText): Ditto.
(WebCore::RenderText::width): Ditto.
* rendering/RenderTextField.cpp:
(WebCore::RenderTextField::updateFromElement): Removed unneeded QChar cast.
(WebCore::RenderTextField::calcMinMaxWidth): Changed from QChar to UChar.
* rendering/bidi.h:
* rendering/bidi.cpp:
(WebCore::BidiIterator::BidiIterator):
(WebCore::BidiState::BidiState):
(WebCore::BidiContext::BidiContext):
(WebCore::bidiNext):
(WebCore::bidiFirst):
(WebCore::BidiIterator::current):
(WebCore::BidiIterator::direction):
(WebCore::addRun):
(WebCore::checkMidpoints):
(WebCore::appendRun):
(WebCore::embed):
(WebCore::RenderBlock::tabWidth):
(WebCore::RenderBlock::computeHorizontalPositionsForLine):
(WebCore::RenderBlock::bidiReorderLine):
(WebCore::RenderBlock::layoutInlineChildren):
(WebCore::skipNonBreakingSpace):
(WebCore::RenderBlock::skipWhitespace):
(WebCore::RenderBlock::findNextLineBreak):
(WebCore::RenderBlock::checkLinesForTextOverflow):
Changed from QChar to UChar and all direction from QChar constants to the
ones from ICU.
* rendering/render_form.cpp:
(WebCore::RenderLineEdit::updateFromElement):
(WebCore::RenderSelect::updateFromElement):
(WebCore::RenderTextArea::updateFromElement):
(WebCore::RenderTextArea::text):
(WebCore::RenderTextArea::textWithHardLineBreaks):
Got rid of now-unneeded QChar type casts.
* rendering/render_line.cpp:
(WebCore::InlineFlowBox::placeBoxesHorizontally): Updated for change from QChar
to UChar.
(WebCore::EllipsisBox::paint): Updated for unicode() -> characters() name change.
* rendering/render_list.cpp:
(WebCore::toRoman): Updated from QChar to UChar.
(WebCore::toLetterString): Ditto.
(WebCore::toHebrew): More of the same, also cleaned up the logic a bit.
(WebCore::RenderListMarker::paint): Removed the alignment parameters from the
various functions. Also removed all reliance on the width-measuring functions
that take a string.
(WebCore::RenderListMarker::calcMinMaxWidth): More of the same.
(WebCore::RenderListMarker::getRelativeMarkerRect): Ditto.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@14273
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2006-05-09 Darin Adler <darin@apple.com>
+
+ - test for http://bugzilla.opendarwin.org/show_bug.cgi?id=6310
+ text-transform: uppercase/lowercase don't handle cases one character becomes two
+
+ * fast/css/case-transform.html: Added.
+ * fast/css/case-transform-expected.txt: Added.
+
2006-05-09 Levi Weintraub <lweintraub@apple.com>
Reviewed by justin.
--- /dev/null
+lower(A𐐀) = a𐐨 (should be a𐐨)
+
+upper(a𐐨) = A𐐀 (should be A𐐀)
+
+lower(ΚΟΣΜΟΣ) = κοσμος (should be κοσμος)
+
+upper(ß) = SS (should be SS)
+
+upper(ʼn) = ʼN (should be ʼN)
+
+upper(ǰ) = J̌ (should be J̌)
+
+upper(ffi) = FFI (should be FFI)
+
+lower(IJ) = ij (should be ij)
+
+
--- /dev/null
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<script>if (window.layoutTestController) layoutTestController.dumpAsText();</script>
+</head>
+<body>
+<p>lower(A𐐀) = <span style="text-transform:lowercase">A𐐀</span> (should be a𐐨)</p>
+<p>upper(a𐐨) = <span style="text-transform:uppercase">a𐐨</span> (should be A𐐀)</p>
+<p>lower(ΚΟΣΜΟΣ) = <span style="text-transform:lowercase">ΚΟΣΜΟΣ</span> (should be κοσμος)</p>
+<p>upper(ß) = <span style="text-transform:uppercase">ß</span> (should be SS)</p>
+<p>upper(ʼn) = <span style="text-transform:uppercase">ʼn</span> (should be ʼN)</p>
+<p>upper(ǰ) = <span style="text-transform:uppercase">ǰ</span> (should be J̌)</p>
+<p>upper(ffi) = <span style="text-transform:uppercase">ffi</span> (should be FFI)</p>
+<p>lower(IJ) = <span style="text-transform:lowercase">IJ</span> (should be ij)</p>
+</body>
+</html>
+2006-05-09 Darin Adler <darin@apple.com>
+
+ Rubber stamped by Hyatt.
+
+ - http://bugzilla.opendarwin.org/show_bug.cgi?id=8782
+ use ICU and UChar more, QChar less
+
+ - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=6310
+ text-transform: uppercase/lowercase don't handle cases one character becomes two
+
+ Test: fast/css/case-transform.html
+
+ By using ICU more, this fixes some bugs in a few places.
+
+ * bindings/js/JSXMLSerializer.cpp:
+ * css/css_valueimpl.h:
+ * kwq/KWQTextStream.cpp:
+ * loader/CachedObject.h:
+ * platform/Color.cpp:
+ Add includes of DeprecatedString.h as needed, now that StringImpl.h no longer
+ includes it.
+
+ * bindings/js/kjs_css.cpp: (KJS::cssPropertyName):
+ Eliminate use of QChar::latin1() in a case where it's not helpful.
+
+ * bindings/js/kjs_proxy.cpp: (WebCore::KJSProxy::evaluate):
+ Use characters() function instead of the old unicode() function.
+
+ * bindings/js/kjs_window.cpp: (KJS::isSeparator):
+ Use UChar instead of QChar.
+
+ * bindings/objc/DOMInternal.mm:
+ (StringImpl::operator NSString*): Remove typecast that's no longer needed.
+ (String::String): Ditto. Also use Vector for local buffer to make code read simpler.
+
+ * bridge/mac/FrameMac.mm:
+ (WebCore::selectorForKeyEvent): Remove call to unicode() function, no longer needed.
+ (WebCore::FrameMac::setTitle): Remove QChar cast, no longer needed.
+ (WebCore::FrameMac::setStatusBarText): Ditto.
+ (WebCore::FrameMac::advanceToNextMisspelling): Use UChar instead of QChar.
+ (WebCore::FrameMac::runJavaScriptAlert): Remove QChar cast, no longer needed.
+ (WebCore::FrameMac::runJavaScriptConfirm): Ditto.
+ (WebCore::FrameMac::runJavaScriptPrompt): Ditto.
+ (WebCore::FrameMac::attributedString): Replaces calls of QChar::direction() with
+ calls to u_charDirection and use ICU constants instead of QChar ones.
+ (WebCore::FrameMac::markMisspellings): Remove QChar cast, no longer needed. Added a
+ QChar cast so we can call isSpace -- slated to be removed later.
+ (WebCore::FrameMac::shouldClose): Remove QChar cast, no longer needed.
+
+ * bridge/mac/WebCoreFrameBridge.mm:
+ (-[WebCoreFrameBridge selectedString]): Remove QChar cast, no longer needed.
+ (-[WebCoreFrameBridge stringForRange:]): Ditto.
+
+ * css/CSSGrammar.y: Update for field name change from string to characters.
+ Use UChar instead of unsigned short.
+
+ * css/css_valueimpl.cpp:
+ (WebCore::propertyID): Use UChar instead of unsigned short and get rid of call to
+ unicode() function, no longer needed.
+ (WebCore::quoteStringIfNeeded): Use strings when building up a resulting string,
+ instead of depending on the feature where you can append characters to a string.
+
+ * css/csshelper.cpp: (WebCore::parseURL): Remove calls to unicode() function and
+ rewrite to obviate the need to call lower() just to check for a few constant
+ character values. Also remove a now-unneeded type cast.
+
+ * css/cssparser.h: Changed ParseString field to use UChar and to be named characters
+ instead of string. Changed many other fields to be UChar instead of unsigned short.
+ (WebCore::domString): Update for that.
+ (WebCore::atomicString): Ditto.
+ * css/cssparser.cpp:
+ (WebCore::ParseString::lower): Use u_tolower instead of QChar::lower(). Also change
+ name to characters from string.
+ (WebCore::CSSParser::setupParser): Use UChar instead of unsigned short.
+ (WebCore::CSSParser::lex): Ditto. Also update for characters name change.
+ (WebCore::CSSParser::text): Use UChar instead of unsigned short. Also tweak some
+ of the code a little bit to handle a couple of overflow cases better and reduce
+ type casting.
+ (WebCore::deprecatedString): Moved here so we don't have to include DeprecatedString.h
+ in the header file.
+
+ * css/cssstyleselector.cpp: (WebCore::checkPseudoState): Added a type cast since this
+ code now bridges the world between modern code and QChar/DeprecatedString.
+
+ * dom/CharacterData.cpp: (WebCore::CharacterData::CharacterData): Changed QChar to UChar.
+
+ * dom/Document.h:
+ * dom/Document.cpp:
+ (WebCore::Document::isValidName): Updated for name change from unicode to characters.
+ (WebCore::Document::parseQualifiedName): Ditto.
+ (WebCore::Document::backslashAsCurrencySymbol): Changed return type to UChar.
+
+ * dom/NamedMappedAttrMap.cpp:
+ (WebCore::isClassWhitespace): Changed parameter to UChar from QChar.
+ (WebCore::NamedMappedAttrMap::parseClassAttribute): Changed from UChar to QChar and
+ from unicode to characters.
+
+ * dom/Position.cpp:
+ (WebCore::Position::leadingWhitespacePosition): Changed from QChar to UChar.
+ (WebCore::Position::trailingWhitespacePosition): Ditto.
+
+ * dom/StyledElement.cpp:
+ (WebCore::isClassWhitespace): Changed from QChar to UChar.
+ (WebCore::StyledElement::addCSSLength): Changed from QChar to UChar, and remove one
+ case where latin1() was used and was not helpful.
+ (WebCore::StyledElement::addCSSColor): Removed unicode() function call, no longer needed.
+
+ * dom/dom2_eventsimpl.cpp: (WebCore::KeyboardEvent::charCode):
+ * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::constrainValue):
+ Removed unicode() function call, no longer needed.
+
+ * dom/xml_tokenizer.h: Removed default parameter for xmlDocPtrForString so we don't have
+ to include the DeprecatedString.h header in this file (and since no one uses it).
+
+ * editing/HTMLInterchange.cpp: (convertHTMLTextToInterchangeFormat): Added a couple calls
+ to the unicode() function to bridge the gap from QChar/DeprecatedString back to modern
+ code.
+
+ * editing/InsertTextCommand.cpp: Removed unused function.
+
+ * editing/TextIterator.h: Changed from QChar to UChar.
+ * editing/TextIterator.cpp:
+ (WebCore::TextIterator::TextIterator): Initialize m_lastCharacter since it's now a UChar
+ (which is just a typedef) rather than a QChar (which was a class with a default value of 0).
+ (WebCore::TextIterator::handleTextNode): Updated to use characters() instead of unicode().
+ (WebCore::TextIterator::handleTextBox): Removed unicode() call since it's now a UChar instead
+ of a QChar.
+ (WebCore::TextIterator::emitCharacter): More of the same.
+ (WebCore::SimplifiedBackwardsTextIterator::handleTextNode): Ditto.
+ (WebCore::SimplifiedBackwardsTextIterator::emitCharacter): Ditto.
+ (WebCore::CharacterIterator::string): Ditto.
+ (WebCore::WordAwareIterator::advance): Ditto.
+ (WebCore::WordAwareIterator::length): Ditto.
+ (WebCore::WordAwareIterator::characters): Ditto.
+ (WebCore::CircularSearchBuffer::CircularSearchBuffer): Changed to use UChar
+ instead of QChar, but also to use foldCase() instead of lower(), because
+ we want case folding here, not lowercasing.
+ (WebCore::CircularSearchBuffer::append): Ditto, with u_foldCase.
+ (WebCore::CircularSearchBuffer::isMatch): Ditto.
+ (WebCore::plainText): Added type cast since this bridges the gap from the modern stuff
+ to QChar/DeprecatedString.
+
+ * editing/VisiblePosition.h: Changed from QChar to UChar.
+ * editing/VisiblePosition.cpp: (WebCore::VisiblePosition::characterAfter): Ditto.
+
+ * editing/markup.cpp: (WebCore::escapeTextForMarkup): Changed code that used latin1()
+ for no good reason to use unicode() instead.
+
+ * html/HTMLTokenizer.h: Changed from QChar to UChar.
+ * html/HTMLTokenizer.cpp: Changed from QChar to UChar, including removing the
+ KHTML_ALLOC_QCHAR_VEC and KHTML_DELETE_QCHAR_VEC macros, which weren't being
+ used consistently anyway.
+ (WebCore::fixUpChar): More of the same.
+ (WebCore::tagMatch): Ditto.
+ (WebCore::HTMLTokenizer::reset): Ditto.
+ (WebCore::HTMLTokenizer::begin): Ditto. Also corrected anomaly where buffer
+ size was not the same as the size value -- this was only true in the initial
+ allocation, so I believe there was no value in it.
+ (WebCore::HTMLTokenizer::parseSpecial): Ditto. Also removed a use of latin1()
+ that was unnnecessary extra work.
+ (WebCore::HTMLTokenizer::scriptHandler): More of the same.
+ (WebCore::HTMLTokenizer::parseComment): Ditto.
+ (WebCore::HTMLTokenizer::parseServer): Ditto.
+ (WebCore::HTMLTokenizer::parseProcessingInstruction): Ditto. Another unnecessary
+ use of latin1() removed.
+ (WebCore::HTMLTokenizer::parseText): Ditto.
+ (WebCore::HTMLTokenizer::parseEntity): Ditto. Changed hex-parsing code to handle
+ uppercase hex a more-efficient way than calling QChar::lower() on each character.
+ Also changed surrogate code logic to fix a couple things -- reject character codes
+ > 0x10FFFF as it should and use U16_LEAD and U16_TRAIL instead of writing our
+ own versions of these.
+ (WebCore::HTMLTokenizer::parseTag): Ditto.
+ (WebCore::HTMLTokenizer::write): Ditto.
+ (WebCore::HTMLTokenizer::end): Ditto.
+ (WebCore::HTMLTokenizer::finish): Ditto.
+ (WebCore::HTMLTokenizer::enlargeBuffer): Ditto.
+ (WebCore::HTMLTokenizer::enlargeScriptBuffer): Ditto.
+ (WebCore::HTMLTokenizer::notifyFinished):
+ (WebCore::decodeNamedEntity): Ditto.
+
+ * html/html_inlineimpl.cpp: (WebCore::parseFontSizeNumber): Changed from QChar
+ to UChar, including using u_isdigit and u_charDigitValue instead of QChar::isNumber
+ and QChar::digitValue. Also removed unneeded range checking that's already done
+ by WebCore::String.
+
+ * kwq/KWQLoader.mm: (KWQIsResponseURLEqualToURL): Rewrote to use Vector and UChar,
+ removing all the type casts and making the whole function much shorter.
+
+ * kwq/WebCoreAXObject.mm:
+ (AXAttributedStringAppendText): Use UChar instead of QChar.
+ (-[WebCoreAXObject doAXAttributedStringForTextMarkerRange:]): More of the same.
+
+ * loader/Cache.h: Remove unnecessary default parameters, preventing the need to
+ include the DeprecatedString.h header in this header. Cleaned up the header
+ structure a bit, removing some obsolete and redundant comments and fixing typos.
+ * loader/Cache.cpp: Removed unused preload functions.
+
+ * page/Frame.h:
+ * page/Frame.cpp:
+ (WebCore::UserStyleSheetLoader::UserStyleSheetLoader): Added explicit arguments.
+ This was the only caller anywhere that took advantage of the default parameter
+ values in one of the Cache class request functions.
+ (WebCore::Frame::backslashAsCurrencySymbol): Changed QChar to UChar.
+
+ * platform/AtomicString.h: Changed QChar to UChar. Removed constructor that makes
+ an AtomicString from a single character. Renamed unicode() function to characters().
+ Renamed KHTML_ATOMICSTRING_HIDE_GLOBALS to ATOMICSTRING_HIDE_GLOBALS.
+ * platform/AtomicString.cpp:
+ (WebCore::CStringTranslator::equal): Changed QChar to UChar.
+ (WebCore::operator==): Changed unicode() to characters().
+ (WebCore::UCharBufferTranslator::hash): More of the same.
+ (WebCore::UCharBufferTranslator::equal): Ditto.
+ (WebCore::UCharBufferTranslator::translate): Ditto.
+ (WebCore::AtomicString::add): Ditto.
+ (WebCore::AtomicString::operator Identifier): Ditto.
+ (WebCore::AtomicString::operator UString): Ditto.
+ (WebCore::AtomicString::AtomicString): Moved here so we don't need DeprecatedString.h
+ in the header.
+ (WebCore::AtomicString::deprecatedString): Ditto.
+
+ * platform/DeprecatedString.h: Removed QChar::Direction enum and all the DirXXX values,
+ isDigit, isLetter, isNumber, isLetterOrNumber, isPunct, digitValue, and direction functions.
+ (QChar::isSpace): Changed to use u_charDirection instead of QChar::direction.
+
+ * platform/Font.h: (WebCore::Font::width): Changed QChar to UChar.
+ * platform/Font.cpp: (WebCore::Font::width): Ditto.
+
+ * platform/GraphicsContext.h:
+ * platform/GraphicsContext.cpp:
+ (WebCore::GraphicsContext::drawText): Changed QChar to UChar. Removed horizontalAlignment
+ parameter from simplified string drawing entry point, since it's not used.
+ (WebCore::GraphicsContext::drawHighlightForText): Changed QChar to UChar.
+
+ * platform/PlatformString.h: Changed QChar to UChar. Removed constructor that makes
+ a String from a single character. Renamed unicode() function to characters(). Added
+ an append function and changed += operator to just call that. Added a foldCase() function.
+ Removed the concatenation operators that add individual strings before or after.
+ * platform/String.cpp:
+ (WebCore::String::String): Changed QChar to UChar.
+ (WebCore::String::append): Renamed from operator+= and removed the return value.
+ (WebCore::String::operator[]): Changed QChar to UChar.
+ (WebCore::String::foldCase): Added.
+ (WebCore::String::percentage): More of the same.
+ (WebCore::String::characters): Renamed from unicode().
+ (WebCore::String::deprecatedString): More of the same.
+ (WebCore::String::sprintf): Fixed mistakes in the comments.
+ (WebCore::String::isEmpty): Tweaked a bit.
+ (WebCore::operator==): More of the same.
+ (WebCore::String::operator Identifier): Ditto.
+ (WebCore::String::operator UString): Ditto.
+
+ * platform/SegmentedString.h: Changed from QChar to UChar. Had to initialize
+ data members that are now UChar.
+ * platform/SegmentedString.cpp:
+ (WebCore::SegmentedString::length): Updated for change from QChar to UChar.
+ (WebCore::SegmentedString::append): Ditto.
+ (WebCore::SegmentedString::prepend): Ditto.
+ (WebCore::SegmentedString::toString): Ditto.
+
+ * platform/StringHash.h: Updated to use UChar instead of QChar and for name changes.
+ Also changed to use case folding intead of lowercasing for case insensitive hashing.
+
+ * platform/StringImpl.h:
+ * platform/StringImpl.cpp:
+ (WebCore::newUCharVector): Changed to UChar from QChar.
+ (WebCore::deleteUCharVector): Ditto.
+ (WebCore::StringImpl::StringImpl): Ditto.
+ (WebCore::StringImpl::init): Ditto. Also renamed from initWithChar and initWithQChar.
+ (WebCore::StringImpl::~StringImpl): Ditto.
+ (WebCore::StringImpl::append): Ditto.
+ (WebCore::StringImpl::insert): Ditto.
+ (WebCore::StringImpl::truncate): Ditto.
+ (WebCore::StringImpl::remove): Ditto.
+ (WebCore::StringImpl::split): Ditto.
+ (WebCore::StringImpl::containsOnlyWhitespace): Ditto. Also added comment because this
+ function seems a little broken.
+ (WebCore::parseLength): More of the same.
+ (WebCore::StringImpl::toCoordsArray): Ditto.
+ (WebCore::StringImpl::toLengthArray): Ditto.
+ (WebCore::StringImpl::isLower): Ditto.
+ (WebCore::StringImpl::lower): Rewrote to use u_strToLower.
+ (WebCore::StringImpl::upper): Rewrote to use u_strToUpper.
+ (WebCore::StringImpl::foldCase): Added. Uses u_strFoldCase.
+ (WebCore::getWordBreakIterator): Changed to use U_FAILURE instead of accepting only
+ U_ZERO_ERROR as a success code.
+ (WebCore::StringImpl::capitalize): More QChar to UChar changes.
+ (WebCore::StringImpl::toInt): Ditto.
+ (WebCore::equal): Changed from QChar to UChar and was careful to preserve the old
+ semantics where "high ASCII" is treated as U+0080-U+00FF even though I don't know
+ if this feature is important.
+ (WebCore::equalIgnoringCase): Ditto, but used case folding instead of lowercasing
+ by using the u_foldCase and u_memcasecmp functions. Also renamed from
+ equalCaseInsensitive for more-consistent naming.
+ (WebCore::StringImpl::find): Ditto. Use case folding for the case insensitive branch.
+ (WebCore::StringImpl::replace): More of the same.
+ (WebCore::StringImpl::computeHash): Ditto.
+ (WebCore::StringImpl::ascii): Ditto.
+
+ * platform/TextBoundaries.h: Changed from QChar to UChar.
+ * platform/mac/TextBoundaries.mm:
+ (WebCore::findWordBoundary): Made the change to UChar and removed some type casts.
+ (WebCore::findNextWordFromIndex): Ditto.
+ (WebCore::findSentenceBoundary): Ditto.
+ (WebCore::findNextSentenceFromIndex): Ditto.
+
+ * platform/TextEncoding.h:
+ * platform/TextEncoding.cpp:
+ (WebCore::TextEncoding::backslashAsCurrencySymbol): Changed from QChar to UChar.
+ (WebCore::TextEncoding::fromUnicode): More of the same.
+ * platform/mac/TextEncodingMac.cpp: (WebCore::TextEncoding::fromUnicode): More
+ of the same.
+
+ * platform/mac/FontFamilyMac.mm: (WebCore::FontFamily::getNSFamily): Removed a
+ now-unneeded type cast.
+
+ * platform/mac/FontMac.mm:
+ (WebCore::Font::selectionRectForText):
+ (WebCore::Font::drawText):
+ (WebCore::Font::drawHighlightForText):
+ (WebCore::Font::floatWidth):
+ (WebCore::Font::checkSelectionPoint):
+ Changed QChar to UChar and removed some now-unneeded type casts.
+
+ * editing/RebalanceWhitespaceCommand.cpp: (WebCore::isWhitespace):
+ * editing/ReplaceSelectionCommand.cpp: (WebCore::ReplaceSelectionCommand::doApply):
+ * editing/visible_units.cpp:
+ (WebCore::previousBoundary):
+ (WebCore::nextBoundary):
+ (WebCore::startWordBoundary):
+ (WebCore::endWordBoundary):
+ (WebCore::previousWordPositionBoundary):
+ (WebCore::nextWordPositionBoundary):
+ (WebCore::startSentenceBoundary):
+ (WebCore::endSentenceBoundary):
+ (WebCore::previousSentencePositionBoundary):
+ (WebCore::nextSentencePositionBoundary):
+ (WebCore::startOfParagraph):
+ (WebCore::endOfParagraph):
+ * html/HTMLParser.cpp: (WebCore::HTMLParser::handleError):
+ * rendering/InlineTextBox.cpp:
+ (WebCore::InlineTextBox::selectionRect):
+ (WebCore::InlineTextBox::paint):
+ (WebCore::InlineTextBox::paintSelection):
+ (WebCore::InlineTextBox::paintMarkedTextBackground):
+ (WebCore::InlineTextBox::paintTextMatchMarker):
+ (WebCore::InlineTextBox::offsetForPosition):
+ (WebCore::InlineTextBox::positionForOffset):
+ * rendering/RenderBlock.cpp:
+ (WebCore::stripTrailingSpace):
+ (WebCore::RenderBlock::updateFirstLetter):
+ * rendering/RenderFlexibleBox.cpp:
+ (WebCore::RenderFlexibleBox::layoutVerticalBox):
+ * rendering/RenderObject.h:
+ * rendering/RenderObject.cpp:
+ (WebCore::RenderObject::backslashAsCurrencySymbol):
+ * rendering/RenderTreeAsText.cpp: (quoteAndEscapeNonPrintables):
+ * rendering/break_lines.cpp: (WebCore::nextBreakablePosition):
+ * rendering/break_lines.h: (WebCore::isBreakable):
+ * rendering/render_style.h: (WebCore::RenderStyle::isCollapsibleWhiteSpace):
+ * xml/XSLStyleSheet.cpp: (WebCore::XSLStyleSheet::parseString):
+ * xml/xmlhttprequest.cpp:
+ (WebCore::getMIMEType):
+ (WebCore::getCharset):
+ Changed QChar to UChar.
+
+ * rendering/RenderImage.cpp:
+ (WebCore::RenderImage::imageChanged): Changed QChar to UChar.
+ (WebCore::RenderImage::paint): Changed callers of drawText to no-longer pass 0
+ for the horizontal alignment, since I removed that parameters.
+
+ * rendering/RenderText.h: Changed QChar to UChar.
+ * rendering/RenderText.cpp:
+ (WebCore::characterBreakIterator): Update for name change.
+ (WebCore::RenderText::RenderText): Ditto.
+ (WebCore::RenderText::allAscii): Remove uneeded unicode() and allow the value
+ U+007F to count as ASCII.
+ (WebCore::RenderText::cacheWidths): Changed QChar to UChar.
+ (WebCore::RenderText::widthFromCache): Changed code that deals with direction to
+ use the ICU direction calls.
+ (WebCore::RenderText::trimmedMinMaxWidth): Changed QChar to UChar.
+ (WebCore::RenderText::calcMinMaxWidth): Ditto.
+ (WebCore::RenderText::containsOnlyWhitespace): Ditto.
+ (WebCore::RenderText::setText): Ditto.
+ (WebCore::RenderText::width): Ditto.
+
+ * rendering/RenderTextField.cpp:
+ (WebCore::RenderTextField::updateFromElement): Removed unneeded QChar cast.
+ (WebCore::RenderTextField::calcMinMaxWidth): Changed from QChar to UChar.
+
+ * rendering/bidi.h:
+ * rendering/bidi.cpp:
+ (WebCore::BidiIterator::BidiIterator):
+ (WebCore::BidiState::BidiState):
+ (WebCore::BidiContext::BidiContext):
+ (WebCore::bidiNext):
+ (WebCore::bidiFirst):
+ (WebCore::BidiIterator::current):
+ (WebCore::BidiIterator::direction):
+ (WebCore::addRun):
+ (WebCore::checkMidpoints):
+ (WebCore::appendRun):
+ (WebCore::embed):
+ (WebCore::RenderBlock::tabWidth):
+ (WebCore::RenderBlock::computeHorizontalPositionsForLine):
+ (WebCore::RenderBlock::bidiReorderLine):
+ (WebCore::RenderBlock::layoutInlineChildren):
+ (WebCore::skipNonBreakingSpace):
+ (WebCore::RenderBlock::skipWhitespace):
+ (WebCore::RenderBlock::findNextLineBreak):
+ (WebCore::RenderBlock::checkLinesForTextOverflow):
+ Changed from QChar to UChar and all direction from QChar constants to the
+ ones from ICU.
+
+ * rendering/render_form.cpp:
+ (WebCore::RenderLineEdit::updateFromElement):
+ (WebCore::RenderSelect::updateFromElement):
+ (WebCore::RenderTextArea::updateFromElement):
+ (WebCore::RenderTextArea::text):
+ (WebCore::RenderTextArea::textWithHardLineBreaks):
+ Got rid of now-unneeded QChar type casts.
+
+ * rendering/render_line.cpp:
+ (WebCore::InlineFlowBox::placeBoxesHorizontally): Updated for change from QChar
+ to UChar.
+ (WebCore::EllipsisBox::paint): Updated for unicode() -> characters() name change.
+
+ * rendering/render_list.cpp:
+ (WebCore::toRoman): Updated from QChar to UChar.
+ (WebCore::toLetterString): Ditto.
+ (WebCore::toHebrew): More of the same, also cleaned up the logic a bit.
+ (WebCore::RenderListMarker::paint): Removed the alignment parameters from the
+ various functions. Also removed all reliance on the width-measuring functions
+ that take a string.
+ (WebCore::RenderListMarker::calcMinMaxWidth): More of the same.
+ (WebCore::RenderListMarker::getRelativeMarkerRect): Ditto.
+
2006-05-09 Tim Omernick <timo@apple.com>
Reviewed by/co-written by Darin.
* css/html4.css:
* css/quirks.css:
-2006-05-06 Darin Adler <darin@apple.com>
+2006-05-07 Darin Adler <darin@apple.com>
Suggested by Mitz. Reviewed and landed by Maciej.
#include "JSXMLSerializer.h"
#include "JSXMLSerializer.lut.h"
+#include "DeprecatedString.h"
#include "PlatformString.h"
#include "kjs_dom.h"
#include "markup.h"
int i = prop.length();
while (--i) {
- char c = prop[i].latin1();
+ ::UChar c = prop[i].unicode();
if (c >= 'A' && c <= 'Z')
prop.insert(i, '-');
}
case AppCodeName:
return jsString("Mozilla");
case AppName:
- // If we find "Mozilla" but not "(compatible, ...)" we are a real Netscape
- if (userAgent.find("Mozilla") >= 0 && userAgent.find("compatible") == -1)
- return jsString("Netscape");
- if (userAgent.find("Microsoft") >= 0 || userAgent.find("MSIE") >= 0)
- return jsString("Microsoft Internet Explorer");
- return jsUndefined();
+ return jsString("Netscape");
case AppVersion:
// We assume the string is something like Mozilla/version (properties)
return jsString(userAgent.substring(userAgent.find('/') + 1));
case Product:
- // When acting normal, we pretend to be "Gecko".
- if (userAgent.find("Mozilla/5.0") >= 0 && userAgent.find("compatible") == -1)
- return jsString("Gecko");
- // When spoofing as IE, we use jsUndefined().
- return jsUndefined();
+ return jsString("Gecko");
case ProductSub:
return jsString("20030107");
case Vendor:
case UserAgent:
return jsString(userAgent);
case Platform:
- if (userAgent.find("Win", 0, false) >= 0)
- return jsString("Win32");
- if (userAgent.find("Macintosh", 0, false) >= 0 || userAgent.find("Mac_PowerPC", 0, false) >= 0)
- return jsString("MacPPC");
- // FIXME: What about Macintosh Intel?
- return jsString("X11");
+#if __APPLE__
+ return jsString("MacPPC");
+#elif WIN32
+ return jsString("Win32");
+#else
+ return jsString("");
+#endif
case _Plugins:
return new Plugins(exec);
case _MimeTypes:
namespace WebCore {
-KJSProxy::KJSProxy(Frame *frame)
+KJSProxy::KJSProxy(Frame* frame)
{
m_script = 0;
m_frame = frame;
Collector::collect();
}
-JSValue* KJSProxy::evaluate(const String& filename, int baseLine, const String& str, Node *n)
+JSValue* KJSProxy::evaluate(const String& filename, int baseLine, const String& str, Node* n)
{
// evaluate code. Returns the JS return value or 0
// if there was none, an error occured or the type couldn't be converted.
JSLock lock;
JSValue* thisNode = n ? Window::retrieve(m_frame) : toJS(m_script->globalExec(), n);
- Completion comp = m_script->evaluate(filename, baseLine, reinterpret_cast<const KJS::UChar *>(str.unicode()), str.length(), thisNode);
+ Completion comp = m_script->evaluate(filename, baseLine, reinterpret_cast<const KJS::UChar*>(str.characters()), str.length(), thisNode);
if (comp.complType() == Normal || comp.complType() == ReturnValue)
return comp.value();
}
}
-EventListener* KJSProxy::createHTMLEventHandler(const String& functionName, const String& code, Node *node)
+EventListener* KJSProxy::createHTMLEventHandler(const String& functionName, const String& code, Node* node)
{
initScriptIfNeeded();
JSLock lock;
}
#if SVG_SUPPORT
-EventListener* KJSProxy::createSVGEventHandler(const String& functionName, const String& code, Node *node)
+EventListener* KJSProxy::createSVGEventHandler(const String& functionName, const String& code, Node* node)
{
initScriptIfNeeded();
JSLock lock;
}
#endif
-void KJSProxy::finishedWithEvent(Event *event)
+void KJSProxy::finishedWithEvent(Event* event)
{
// This is called when the DOM implementation has finished with a particular event. This
// is the case in sitations where an event has been created just for temporary usage,
m_script->forgetDOMObject(event);
}
-ScriptInterpreter *KJSProxy::interpreter()
+ScriptInterpreter* KJSProxy::interpreter()
{
initScriptIfNeeded();
assert(m_script);
class TestFunctionImp : public DOMObject {
public:
virtual bool implementsCall() const { return true; }
- virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
+ virtual JSValue* callAsFunction(ExecState*, JSObject*, const List& args);
};
-JSValue *TestFunctionImp::callAsFunction(ExecState *exec, JSObject */*thisObj*/, const List &args)
+JSValue *TestFunctionImp::callAsFunction(ExecState* exec, JSObject*, const List& args)
{
- fprintf(stderr,"--> %s\n",args[0]->toString(exec).ascii());
+ fprintf(stderr,"--> %s\n", args[0]->toString(exec).ascii());
return jsUndefined();
}
}
// Though isspace() considers \t and \v to be whitespace, Win IE doesn't.
-static bool isSeparator(QChar c)
+static bool isSeparator(UChar c)
{
return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '=' || c == ',' || c == '\0';
}
StringImpl::operator NSString *() const
{
- return [NSString stringWithCharacters:reinterpret_cast<const unichar *>(m_data) length:m_length];
+ return [NSString stringWithCharacters:m_data length:m_length];
}
-String::String(NSString *str)
+String::String(NSString* str)
{
if (!str)
return;
if (size == 0)
m_impl = StringImpl::empty();
else {
- UniChar fixedSizeBuffer[1024];
- UniChar *buffer;
- if (size > static_cast<CFIndex>(sizeof(fixedSizeBuffer) / sizeof(UniChar)))
- buffer = static_cast<UniChar *>(fastMalloc(size * sizeof(UniChar)));
- else
- buffer = fixedSizeBuffer;
- CFStringGetCharacters(reinterpret_cast<CFStringRef>(str), CFRangeMake(0, size), buffer);
- m_impl = new StringImpl(reinterpret_cast<const QChar *>(buffer), (unsigned)size);
- if (buffer != fixedSizeBuffer)
- fastFree(buffer);
+ Vector<UChar, 1024> buffer(size);
+ CFStringGetCharacters(reinterpret_cast<CFStringRef>(str), CFRangeMake(0, size), buffer.data());
+ m_impl = new StringImpl(buffer.data(), size);
}
}
@end
using namespace std;
-
-using namespace KJS;
-using namespace Bindings;
-
+using namespace KJS::Bindings;
using namespace KIO;
+using KJS::JSLock;
+using KJS::PausedTimeouts;
+using KJS::SavedBuiltins;
+using KJS::SavedProperties;
+
namespace WebCore {
using namespace EventNames;
using namespace HTMLNames;
-NSEvent *FrameMac::_currentEvent = nil;
+NSEvent* FrameMac::_currentEvent = nil;
static NSMutableDictionary* createNSDictionary(const HashMap<String, String>& map)
{
return 0;
SEL selector = NULL;
- switch (key[0U].unicode()) {
+ switch (key[0U]) {
case NSUpArrowFunctionKey:
selector = @selector(moveUp:); break;
case NSDownArrowFunctionKey:
void FrameMac::setTitle(const String &title)
{
String text = title;
- text.replace(QChar('\\'), backslashAsCurrencySymbol());
+ text.replace('\\', backslashAsCurrencySymbol());
BEGIN_BLOCK_OBJC_EXCEPTIONS;
[_bridge setTitle:text];
void FrameMac::setStatusBarText(const String& status)
{
String text = status;
- text.replace(QChar('\\'), backslashAsCurrencySymbol());
+ text.replace('\\', backslashAsCurrencySymbol());
BEGIN_BLOCK_OBJC_EXCEPTIONS;
[_bridge setStatusText:text];
while (1) {
if (!it.atEnd()) { // we may be starting at the end of the doc, and already by atEnd
- const QChar *chars = it.characters();
+ const UChar* chars = it.characters();
int len = it.length();
- if (len > 1 || !chars[0].isSpace()) {
- NSString *chunk = [[NSString alloc] initWithCharactersNoCopy:(unichar *)chars length:len freeWhenDone:NO];
+ if (len > 1 || !QChar(chars[0]).isSpace()) {
+ NSString *chunk = [[NSString alloc] initWithCharactersNoCopy:const_cast<UChar*>(chars) length:len freeWhenDone:NO];
NSRange misspelling = [checker checkSpellingOfString:chunk startingAt:0 language:nil wrap:NO inSpellDocumentWithTag:[_bridge spellCheckerDocumentTag] wordCount:NULL];
[chunk release];
if (misspelling.length > 0) {
void FrameMac::runJavaScriptAlert(const String& message)
{
String text = message;
- text.replace(QChar('\\'), backslashAsCurrencySymbol());
+ text.replace('\\', backslashAsCurrencySymbol());
BEGIN_BLOCK_OBJC_EXCEPTIONS;
[_bridge runJavaScriptAlertPanelWithMessage:text];
END_BLOCK_OBJC_EXCEPTIONS;
bool FrameMac::runJavaScriptConfirm(const String& message)
{
String text = message;
- text.replace(QChar('\\'), backslashAsCurrencySymbol());
+ text.replace('\\', backslashAsCurrencySymbol());
BEGIN_BLOCK_OBJC_EXCEPTIONS;
return [_bridge runJavaScriptConfirmPanelWithMessage:text];
bool FrameMac::runJavaScriptPrompt(const String& prompt, const String& defaultValue, String& result)
{
String promptText = prompt;
- promptText.replace(QChar('\\'), backslashAsCurrencySymbol());
+ promptText.replace('\\', backslashAsCurrencySymbol());
String defaultValueText = defaultValue;
- defaultValueText.replace(QChar('\\'), backslashAsCurrencySymbol());
+ defaultValueText.replace('\\', backslashAsCurrencySymbol());
bool ok;
BEGIN_BLOCK_OBJC_EXCEPTIONS;
if (ok) {
result = String(returnedText);
- result.replace(backslashAsCurrencySymbol(), QChar('\\'));
+ result.replace(backslashAsCurrencySymbol(), '\\');
}
return ok;
text += str.mid(runStart, runEnd-runStart);
[pendingStyledSpace release];
pendingStyledSpace = nil;
- addedSpace = str[runEnd-1].direction() == QChar::DirWS;
+ addedSpace = u_charDirection(str[runEnd - 1].unicode()) == U_WHITE_SPACE_NEUTRAL;
}
else {
RenderText* textObj = static_cast<RenderText*>(renderer);
needSpace = nextRunStart > runEnd;
[pendingStyledSpace release];
pendingStyledSpace = nil;
- addedSpace = str[runEnd-1].direction() == QChar::DirWS;
+ addedSpace = u_charDirection(str[runEnd - 1].unicode()) == U_WHITE_SPACE_NEUTRAL;
start = -1;
}
if (end != -1 && runEnd >= end)
}
}
- text.replace(QChar('\\'), renderer->backslashAsCurrencySymbol());
+ text.replace('\\', renderer->backslashAsCurrencySymbol());
if (text.length() > 0 || needSpace) {
NSMutableDictionary *attrs = [[NSMutableDictionary alloc] init];
WordAwareIterator it(searchRange.get());
while (!it.atEnd()) { // we may be starting at the end of the doc, and already by atEnd
- const QChar *chars = it.characters();
+ const UChar* chars = it.characters();
int len = it.length();
- if (len > 1 || !chars[0].isSpace()) {
- NSString *chunk = [[NSString alloc] initWithCharactersNoCopy:(unichar *)chars length:len freeWhenDone:NO];
+ if (len > 1 || !QChar(chars[0]).isSpace()) {
+ NSString *chunk = [[NSString alloc] initWithCharactersNoCopy:const_cast<UChar*>(chars) length:len freeWhenDone:NO];
int startIndex = 0;
// Loop over the chunk to find each misspelling in it.
while (startIndex < len) {
return true;
String text = event->result();
- text.replace(QChar('\\'), backslashAsCurrencySymbol());
+ text.replace('\\', backslashAsCurrencySymbol());
return [_bridge runBeforeUnloadConfirmPanelWithMessage:text];
- (NSString *)selectedString
{
String text = m_frame->selectedText();
- text.replace(QChar('\\'), m_frame->backslashAsCurrencySymbol());
+ text.replace('\\', m_frame->backslashAsCurrencySymbol());
return [[(NSString*)text copy] autorelease];
}
- (NSString *)stringForRange:(DOMRange *)range
{
String text = plainText([range _range]);
- text.replace(QChar('\\'), m_frame->backslashAsCurrencySymbol());
+ text.replace('\\', m_frame->backslashAsCurrencySymbol());
return [[(NSString*)text copy] autorelease];
}
namespace WebCore {
-int getPropertyID(const char *tagStr, int len)
+int getPropertyID(const char* tagStr, int len)
{
DeprecatedString prop;
len = strlen(opacity);
}
}
-
- const struct props *propsPtr = findProp(tagStr, len);
+
+ const struct props* propsPtr = findProp(tagStr, len);
if (!propsPtr)
return 0;
}
-static inline int getValueID(const char *tagStr, int len)
+static inline int getValueID(const char* tagStr, int len)
{
DeprecatedString prop;
if (len && tagStr[0] == '-') {
;
maybe_ns_prefix:
-/* empty */ { $$.string = 0; }
+/* empty */ { $$.characters = 0; }
| IDENT WHITESPACE { $$ = $1; }
;
media_list:
medium {
$$ = static_cast<CSSParser*>(parser)->createMediaList();
- $$->appendMedium( domString($1).lower() );
+ $$->appendMedium(domString($1).lower());
}
| media_list ',' maybe_space medium {
$$ = $1;
if ($$)
- $$->appendMedium( domString($4) );
+ $$->appendMedium(domString($4).lower());
}
| media_list error {
$$ = 0;
;
namespace_selector:
- /* empty */ '|' { $$.string = 0; $$.length = 0; }
- | '*' '|' { static unsigned short star = '*'; $$.string = ☆ $$.length = 1; }
+ /* empty */ '|' { $$.characters = 0; $$.length = 0; }
+ | '*' '|' { static UChar star = '*'; $$.characters = ☆ $$.length = 1; }
| IDENT '|' { $$ = $1; }
;
$$ = str;
}
| '*' {
- static unsigned short star = '*';
- $$.string = ☆
+ static UChar star = '*';
+ $$.characters = ☆
$$.length = 1;
}
;
property:
IDENT maybe_space {
+ $1.lower();
DeprecatedString str = deprecatedString($1);
- $$ = getPropertyID(str.lower().latin1(), str.length());
+ const char* s = str.ascii();
+ int l = str.length();
+ $$ = getPropertyID(s, l);
#if SVG_SUPPORT
- if ($$ == 0)
- $$ = SVG::getSVGCSSPropertyID(str.lower().latin1(), str.length());
+ if ($$ == 0)
+ $$ = SVG::getSVGCSSPropertyID(s, l);
#endif
}
;
namespace WebCore {
// Defined in CSSGrammar.y, but not in any header, so just declare it here for now.
-int getPropertyID(const char *str, int len);
+int getPropertyID(const char* str, int len);
-static int propertyID(const String &s)
+static int propertyID(const String& s)
{
char buffer[maxCSSPropertyNameLength];
return 0;
for (unsigned i = 0; i != len; ++i) {
- unsigned short c = s[i].unicode();
+ UChar c = s[i];
if (c == 0 || c >= 0x7F)
return 0; // illegal character
buffer[i] = c;
String s = string;
s.replace('\\', "\\\\");
s.replace('\'', "\\'");
- return '\'' + s + '\'';
+ return "'" + s + "'";
}
CSSStyleDeclaration::CSSStyleDeclaration(CSSRule *parent)
#include "CachedObjectClient.h"
#include "css_base.h"
#include "DeprecatedPtrList.h"
+#include "DeprecatedString.h"
#include "DeprecatedValueList.h"
#include <wtf/PassRefPtr.h>
int o = 0;
int l = i->length();
- while (o < l && (*i)[o].unicode() <= ' ') {
+ while (o < l && (*i)[o] <= ' ') {
++o;
--l;
}
- while (l > 0 && (*i)[o+l-1].unicode() <= ' ')
+ while (l > 0 && (*i)[o+l-1] <= ' ')
--l;
if (l >= 5
- && (*i)[o].lower() == 'u'
- && (*i)[o + 1].lower() == 'r'
- && (*i)[o + 2].lower() == 'l'
+ && ((*i)[o] == 'u' || (*i)[o] == 'U')
+ && ((*i)[o + 1] == 'r' || (*i)[o + 1] == 'R')
+ && ((*i)[o + 2] == 'l' || (*i)[o + 2] == 'L')
&& (*i)[o + 3] == '('
&& (*i)[o + l - 1] == ')') {
o += 4;
l -= 5;
}
- while (o < l && (*i)[o].unicode() <= ' ') {
+ while (o < l && (*i)[o] <= ' ') {
++o;
--l;
}
- while (l > 0 && (*i)[o+l-1].unicode() <= ' ')
+ while (l > 0 && (*i)[o+l-1] <= ' ')
--l;
if (l >= 2 && (*i)[o] == (*i)[o+l-1] && ((*i)[o] == '\'' || (*i)[o] == '\"')) {
l -= 2;
}
- while (o < l && (*i)[o].unicode() <= ' ') {
+ while (o < l && (*i)[o] <= ' ') {
++o;
--l;
}
- while (l > 0 && (*i)[o+l-1].unicode() <= ' ')
+ while (l > 0 && (*i)[o+l-1] <= ' ')
--l;
- Vector<unsigned short, 2048> buffer(l);
+ Vector<UChar, 2048> buffer(l);
int nl = 0;
for (int k = o; k < o + l; k++) {
- unsigned short c = (*i)[k].unicode();
+ UChar c = (*i)[k];
if (c > '\r')
buffer[nl++] = c;
}
- return new StringImpl(reinterpret_cast<QChar*>(buffer.data()), nl);
+ return new StringImpl(buffer.data(), nl);
}
}
void ParseString::lower()
{
+ // Fast case for all-ASCII.
+ UChar ored = 0;
for (int i = 0; i < length; i++)
- string[i] = QChar(string[i]).lower().unicode();
+ ored |= characters[i];
+ if (ored & ~0x7F)
+ for (int i = 0; i < length; i++)
+ characters[i] = u_tolower(characters[i]);
+ else
+ for (int i = 0; i < length; i++)
+ characters[i] = tolower(characters[i]);
}
void CSSParser::setupParser(const char* prefix, const String& string, const char* suffix)
{
int length = string.length() + strlen(prefix) + strlen(suffix) + 2;
- data = (unsigned short*)fastMalloc(length * sizeof(unsigned short));
+ data = static_cast<UChar*>(fastMalloc(length * sizeof(UChar)));
for (unsigned i = 0; i < strlen(prefix); i++)
data[i] = prefix[i];
- memcpy(data + strlen(prefix), string.unicode(), string.length() * sizeof(unsigned short));
+ memcpy(data + strlen(prefix), string.characters(), string.length() * sizeof(UChar));
unsigned start = strlen(prefix) + string.length();
unsigned end = start + strlen(suffix);
#include "CSSGrammar.h"
-int CSSParser::lex(void *_yylval) {
- YYSTYPE *yylval = (YYSTYPE *)_yylval;
+int CSSParser::lex(void* yylvalWithoutType)
+{
+ YYSTYPE* yylval = static_cast<YYSTYPE*>(yylvalWithoutType);
int token = lex();
int length;
- unsigned short *t = text(&length);
+ UChar* t = text(&length);
#ifdef TOKEN_DEBUG
qDebug("CSSTokenizer: got token %d: '%s'", token, token == END_TOKEN ? "" : DeprecatedString((QChar *)t, length).latin1());
case DIMEN:
case UNICODERANGE:
case FUNCTION:
- yylval->string.string = t;
+ yylval->string.characters = t;
yylval->string.length = length;
break;
return 0;
}
-unsigned short *CSSParser::text(int *length)
+UChar* CSSParser::text(int *length)
{
- unsigned short *start = yytext;
+ UChar* start = yytext;
int l = yyleng;
switch(yyTok) {
case STRING:
}
// process escapes
- unsigned short *out = start;
- unsigned short *escape = 0;
+ UChar* out = start;
+ UChar* escape = 0;
for (int i = 0; i < l; i++) {
- unsigned short *current = start+i;
+ UChar* current = start + i;
if (escape == current - 1) {
if ((*current >= '0' && *current <= '9') ||
(*current >= 'a' && *current <= 'f') ||
continue;
if (escape) {
// add escaped char
- int uc = 0;
+ unsigned uc = 0;
escape++;
while (escape < current) {
uc *= 16;
// can't handle chars outside ucs2
if (uc > 0xffff)
uc = 0xfffd;
- *(out++) = (unsigned short)uc;
+ *out++ = uc;
escape = 0;
if (*current == ' ' ||
*current == '\t' ||
escape = current;
continue;
}
- *(out++) = *current;
+ *out++ = *current;
}
if (escape) {
// add escaped char
- int uc = 0;
+ unsigned uc = 0;
escape++;
while (escape < start+l) {
uc *= 16;
// can't handle chars outside ucs2
if (uc > 0xffff)
uc = 0xfffd;
- *(out++) = (unsigned short)uc;
+ *out++ = uc;
}
*length = out - start;
return rule;
}
+DeprecatedString deprecatedString(const ParseString& ps)
+{
+ return DeprecatedString(reinterpret_cast<const QChar*>(ps.characters), ps.length);
+}
+
#define YY_DECL int CSSParser::lex()
#define yyconst const
typedef int yy_state_type;
class StyleList;
struct ParseString {
- unsigned short* string;
+ UChar* characters;
int length;
void lower();
int unit;
};
- static inline DeprecatedString deprecatedString(const ParseString& ps) {
- return DeprecatedString((QChar *)ps.string, ps.length);
- }
+ DeprecatedString deprecatedString(const ParseString&);
static inline String domString(const ParseString& ps) {
- return String((QChar *)ps.string, ps.length);
+ return String(ps.characters, ps.length);
}
static inline AtomicString atomicString(const ParseString& ps) {
- return AtomicString(ps.string, ps.length);
+ return AtomicString(ps.characters, ps.length);
}
class ValueList {
public:
int lex(void* yylval);
int token() { return yyTok; }
- unsigned short* text(int* length);
+ UChar* text(int* length);
int lex();
private:
bool inShorthand() const { return m_inParseShorthand; }
- unsigned short* data;
- unsigned short* yytext;
- unsigned short* yy_c_buf_p;
- unsigned short yy_hold_char;
+ UChar* data;
+ UChar* yytext;
+ UChar* yy_c_buf_p;
+ UChar yy_hold_char;
int yy_last_accepting_state;
- unsigned short* yy_last_accepting_cpos;
+ UChar* yy_last_accepting_cpos;
int yyleng;
int yyTok;
int yy_start;
return;
}
- QConstString cu(attr.unicode(), attr.length());
+ QConstString cu(reinterpret_cast<const QChar*>(attr.characters()), attr.length());
DeprecatedString u = cu.string();
if (!u.contains("://")) {
if (u[0] == '/')
CharacterData::CharacterData(Document *doc, const String &_text)
: EventTargetNode(doc)
{
- str = _text.impl() ? _text.impl() : new StringImpl((QChar*)0, 0);
+ str = _text.impl() ? _text.impl() : new StringImpl(static_cast<UChar*>(0), 0);
str->ref();
}
bool Document::isValidName(const String &name)
{
- const UChar *s = reinterpret_cast<const UChar *>(name.unicode());
+ const UChar* s = reinterpret_cast<const UChar*>(name.characters());
unsigned length = name.length();
if (length == 0)
bool sawColon = false;
int colonPos = 0;
- const UChar* s = reinterpret_cast<const UChar*>(qualifiedName.unicode());
+ const UChar* s = reinterpret_cast<const UChar*>(qualifiedName.characters());
for (unsigned i = 0; i < length;) {
UChar32 c;
U16_NEXT(s, i, length, c)
m_decoder = decoder;
}
-QChar Document::backslashAsCurrencySymbol() const
+UChar Document::backslashAsCurrencySymbol() const
{
if (!m_decoder)
return '\\';
}
#if XPATH_SUPPORT
+
PassRefPtr<XPathExpression> Document::createExpression(const String& expression,
XPathNSResolver* resolver,
ExceptionCode& ec)
{
if (!m_xpathEvaluator)
m_xpathEvaluator = new XPathEvaluator;
-
return m_xpathEvaluator->createExpression(expression, resolver, ec);
}
-PassRefPtr<XPathNSResolver> Document::createNSResolver(Node *nodeResolver)
+PassRefPtr<XPathNSResolver> Document::createNSResolver(Node* nodeResolver)
{
if (!m_xpathEvaluator)
m_xpathEvaluator = new XPathEvaluator;
-
return m_xpathEvaluator->createNSResolver(nodeResolver);
}
{
if (!m_xpathEvaluator)
m_xpathEvaluator = new XPathEvaluator;
-
return m_xpathEvaluator->evaluate(expression, contextNode, resolver, type, result, ec);
}
void setDecoder(Decoder*);
Decoder* decoder() const { return m_decoder.get(); }
- QChar backslashAsCurrencySymbol() const;
+ UChar backslashAsCurrencySymbol() const;
#if __APPLE__
void setDashboardRegionsDirty(bool f) { m_dashboardRegionsDirty = f; }
return true;
}
-inline static bool isClassWhitespace(QChar c)
+inline static bool isClassWhitespace(UChar c)
{
return c == ' ' || c == '\r' || c == '\n' || c == '\t';
}
AtomicStringList* curr = 0;
- const QChar* str = classAttr.unicode();
+ const UChar* str = classAttr.characters();
int length = classAttr.length();
int sPos = 0;
using namespace HTMLNames;
+const UChar nonBreakingSpace = 0xa0;
+
static Node *nextRenderedEditable(Node *node)
{
while (1) {
Position prev = previousCharacterPosition(affinity);
if (prev != *this && prev.node()->inSameContainingBlockFlowElement(node()) && prev.node()->isTextNode()) {
String string = static_cast<Text *>(prev.node())->data();
- const QChar &c = string[prev.offset()];
- if (considerNonCollapsibleWhitespace ? (c.isSpace() || c.unicode() == 0xa0) : isCollapsibleWhitespace(c))
+ UChar c = string[prev.offset()];
+ if (considerNonCollapsibleWhitespace ? (QChar(c).isSpace() || c == nonBreakingSpace) : isCollapsibleWhitespace(c))
return prev;
}
return Position();
if (node()->isTextNode()) {
- Text *textNode = static_cast<Text *>(node());
+ Text* textNode = static_cast<Text*>(node());
if (offset() < (int)textNode->length()) {
- String string = static_cast<Text *>(node())->data();
- const QChar &c = string[offset()];
- if (considerNonCollapsibleWhitespace ? (c.isSpace() || c.unicode() == 0xa0) : isCollapsibleWhitespace(c))
+ String string = textNode->data();
+ UChar c = string[offset()];
+ if (considerNonCollapsibleWhitespace ? (QChar(c).isSpace() || c == nonBreakingSpace) : isCollapsibleWhitespace(c))
return *this;
return Position();
}
Position next = nextCharacterPosition(affinity);
if (next != *this && next.node()->inSameContainingBlockFlowElement(node()) && next.node()->isTextNode()) {
- String string = static_cast<Text *>(next.node())->data();
- const QChar &c = string[0];
- if (considerNonCollapsibleWhitespace ? (c.isSpace() || c.unicode() == 0xa0) : isCollapsibleWhitespace(c))
+ String string = static_cast<Text*>(next.node())->data();
+ UChar c = string[0];
+ if (considerNonCollapsibleWhitespace ? (QChar(c).isSpace() || c == nonBreakingSpace) : isCollapsibleWhitespace(c))
return next;
}
}
}
-inline static bool isClassWhitespace(QChar c)
+inline static bool isClassWhitespace(UChar c)
{
return c == ' ' || c == '\r' || c == '\n' || c == '\t';
}
if (v) {
unsigned int l = 0;
- while (l < v->length() && (*v)[l].unicode() <= ' ')
+ while (l < v->length() && (*v)[l] <= ' ')
l++;
for (; l < v->length(); l++) {
- char cc = (*v)[l].latin1();
+ UChar cc = (*v)[l];
if (cc > '9' || (cc < '0' && cc != '*' && cc != '%' && cc != '.'))
break;
}
// search forward for digits in the string
int numDigits = 0;
while (pos < (int)color.length() && numDigits < basicLength) {
- int hex = toHex(color[pos].unicode());
+ int hex = toHex(color[pos]);
colors[component] = (colors[component] << 4);
if (hex > 0) {
colors[component] += hex;
String text = m_keyEvent->text();
if (text.length() != 1)
return 0;
- return text[0].unicode();
+ return text[0];
}
bool KeyboardEvent::isKeyboardEvent() const
Tokenizer* newXMLTokenizer(Document*, FrameView* = 0);
#if KHTML_XSLT
-void* xmlDocPtrForString(const DeprecatedString& source, const DeprecatedString& URL = DeprecatedString());
+void* xmlDocPtrForString(const DeprecatedString& source, const DeprecatedString& URL);
void setLoaderForLibXMLCallbacks(DocLoader*);
#endif
HashMap<String, String> parseAttributes(const String&, bool& attrsOK);
unsigned int consumed = 0;
while (i < in.length()) {
consumed = 1;
- if (isCollapsibleWhitespace(in[i])) {
+ if (isCollapsibleWhitespace(in[i].unicode())) {
// count number of adjoining spaces
unsigned int j = i + 1;
- while (j < in.length() && isCollapsibleWhitespace(in[j]))
+ while (j < in.length() && isCollapsibleWhitespace(in[j].unicode()))
j++;
unsigned int count = j - i;
consumed = count;
return pos;
}
-static inline bool isNBSP(const QChar &c)
-{
- return c.unicode() == 0xa0;
-}
-
void InsertTextCommand::input(const String &text, bool selectInsertedText)
{
assert(text.find('\n') == -1);
{
}
-static inline bool isWhitespace(const QChar &c)
+static inline bool isWhitespace(UChar c)
{
- return c.unicode() == 0xa0 || isCollapsibleWhitespace(c);
+ return c == 0xa0 || isCollapsibleWhitespace(c);
}
// FIXME: This doesn't go into adjacent text in siblings, cousins, etc.
assert(visiblePos.isNotNull());
addLeadingSpace = startPos.leadingWhitespacePosition(VP_DEFAULT_AFFINITY, true).isNull() && !isStartOfParagraph(visiblePos);
if (addLeadingSpace) {
- QChar previousChar = visiblePos.previous().characterAfter();
- if (previousChar.unicode())
+ UChar previousChar = visiblePos.previous().characterAfter();
+ if (previousChar)
addLeadingSpace = !frame->isCharacterSmartReplaceExempt(previousChar, true);
}
addTrailingSpace = startPos.trailingWhitespacePosition(VP_DEFAULT_AFFINITY, true).isNull() && !isEndOfParagraph(visiblePos);
if (addTrailingSpace) {
- QChar thisChar = visiblePos.characterAfter();
- if (thisChar.unicode())
+ UChar thisChar = visiblePos.characterAfter();
+ if (thisChar)
addTrailingSpace = !frame->isCharacterSmartReplaceExempt(thisChar, false);
}
}
using namespace HTMLNames;
-const unsigned short nonBreakingSpace = 0xA0;
+const UChar nonBreakingSpace = 0xA0;
// Buffer that knows how to compare with a search target.
// Keeps enough of the previous text to be able to search in the future,
~CircularSearchBuffer() { fastFree(m_buffer); }
void clear() { m_cursor = m_buffer; m_bufferFull = false; }
- void append(int length, const QChar *characters);
- void append(const QChar&);
+ void append(int length, const UChar* characters);
+ void append(UChar);
int neededCharacters() const;
bool isMatch() const;
String m_target;
bool m_isCaseSensitive;
- QChar *m_buffer;
- QChar *m_cursor;
+ UChar* m_buffer;
+ UChar* m_cursor;
bool m_bufferFull;
CircularSearchBuffer(const CircularSearchBuffer&);
CircularSearchBuffer &operator=(const CircularSearchBuffer&);
};
-TextIterator::TextIterator() : m_endContainer(0), m_endOffset(0), m_positionNode(0)
+TextIterator::TextIterator() : m_endContainer(0), m_endOffset(0), m_positionNode(0), m_lastCharacter(0)
{
}
m_positionOffsetBaseNode = 0;
m_positionStartOffset = runStart;
m_positionEndOffset = runEnd;
- m_textCharacters = str.unicode() + runStart;
+ m_textCharacters = str.characters() + runStart;
m_textLength = runEnd - runStart;
m_lastCharacter = str[runEnd - 1];
InlineTextBox *firstTextBox = renderer->containsReversedText() ? m_sortedTextBoxes[0] : renderer->firstTextBox();
bool needSpace = m_lastTextNodeEndedWithCollapsedSpace
|| (m_textBox == firstTextBox && textBoxStart == runStart && runStart > 0);
- if (needSpace && !isCollapsibleWhitespace(m_lastCharacter) && m_lastCharacter.unicode()) {
+ if (needSpace && !isCollapsibleWhitespace(m_lastCharacter) && m_lastCharacter) {
emitCharacter(' ', m_node, 0, runStart, runStart);
return;
}
m_positionOffsetBaseNode = 0;
m_positionStartOffset = runStart;
m_positionEndOffset = subrunEnd;
- m_textCharacters = str.unicode() + runStart;
+ m_textCharacters = str.characters() + runStart;
m_textLength = subrunEnd - runStart;
m_lastTextNodeEndedWithCollapsedSpace = false;
emitCharacter(' ', m_node->parentNode(), m_node, 1, 1);
}
-void TextIterator::emitCharacter(QChar c, Node *textNode, Node *offsetBaseNode, int textStartOffset, int textEndOffset)
+void TextIterator::emitCharacter(UChar c, Node *textNode, Node *offsetBaseNode, int textStartOffset, int textEndOffset)
{
// remember information with which to construct the TextIterator::range()
// NOTE: textNode is often not a text node, so the range will specify child nodes of positionNode
m_positionNode = m_node;
m_positionStartOffset = m_offset;
m_textLength = m_positionEndOffset - m_positionStartOffset;
- m_textCharacters = str.unicode() + m_positionStartOffset;
+ m_textCharacters = str.characters() + m_positionStartOffset;
m_lastCharacter = str[m_positionEndOffset - 1];
handleNonTextNode();
}
-void SimplifiedBackwardsTextIterator::emitCharacter(QChar c, Node *node, int startOffset, int endOffset)
+void SimplifiedBackwardsTextIterator::emitCharacter(UChar c, Node *node, int startOffset, int endOffset)
{
m_singleCharacterBuffer = c;
m_positionNode = node;
result.reserve(numChars);
while (numChars > 0 && !atEnd()) {
int runSize = min(numChars, length());
- result.append(characters(), runSize);
+ result.append(reinterpret_cast<const QChar*>(characters()), runSize);
numChars -= runSize;
advance(runSize);
}
while (1) {
// If this chunk ends in whitespace we can just use it as our chunk.
- if (m_textIterator.characters()[m_textIterator.length()-1].isSpace())
+ if (QChar(m_textIterator.characters()[m_textIterator.length() - 1]).isSpace())
return;
// If this is the first chunk that failed, save it in previousText before look ahead
// Look ahead to next chunk. If it is whitespace or a break, we can use the previous stuff
m_textIterator.advance();
- if (m_textIterator.atEnd() || m_textIterator.length() == 0 || m_textIterator.characters()[0].isSpace()) {
+ if (m_textIterator.atEnd() || m_textIterator.length() == 0 || QChar(m_textIterator.characters()[0]).isSpace()) {
m_didLookAhead = true;
return;
}
if (m_buffer.isEmpty()) {
// Start gobbling chunks until we get to a suitable stopping point
- m_buffer.append(m_previousText, m_previousLength);
+ m_buffer.append(reinterpret_cast<const QChar*>(m_previousText), m_previousLength);
m_previousText = 0;
}
- m_buffer.append(m_textIterator.characters(), m_textIterator.length());
+ m_buffer.append(reinterpret_cast<const QChar*>(m_textIterator.characters()), m_textIterator.length());
int exception = 0;
m_range->setEnd(m_textIterator.range()->endContainer(exception), m_textIterator.range()->endOffset(exception), exception);
}
{
if (!m_buffer.isEmpty())
return m_buffer.length();
- else if (m_previousText)
+ if (m_previousText)
return m_previousLength;
- else
- return m_textIterator.length();
+ return m_textIterator.length();
}
-const QChar *WordAwareIterator::characters() const
+const UChar* WordAwareIterator::characters() const
{
if (!m_buffer.isEmpty())
- return m_buffer.unicode();
- else if (m_previousText)
+ return reinterpret_cast<const UChar*>(m_buffer.unicode());
+ if (m_previousText)
return m_previousText;
- else
- return m_textIterator.characters();
+ return m_textIterator.characters();
}
CircularSearchBuffer::CircularSearchBuffer(const String& s, bool isCaseSensitive)
assert(!s.isEmpty());
if (!isCaseSensitive)
- m_target = s.lower();
+ m_target = s.foldCase();
m_target.replace(nonBreakingSpace, ' ');
m_isCaseSensitive = isCaseSensitive;
- m_buffer = static_cast<QChar *>(fastMalloc(s.length() * sizeof(QChar)));
+ m_buffer = static_cast<UChar*>(fastMalloc(s.length() * sizeof(UChar)));
m_cursor = m_buffer;
m_bufferFull = false;
}
-void CircularSearchBuffer::append(const QChar &c)
+void CircularSearchBuffer::append(UChar c)
{
if (m_isCaseSensitive)
- *m_cursor++ = c.unicode() == nonBreakingSpace ? ' ' : c.unicode();
+ *m_cursor++ = c == nonBreakingSpace ? ' ' : c;
else
- *m_cursor++ = c.unicode() == nonBreakingSpace ? ' ' : c.lower().unicode();
+ *m_cursor++ = c == nonBreakingSpace ? ' ' : u_foldCase(c, U_FOLD_CASE_DEFAULT);
if (m_cursor == m_buffer + length()) {
m_cursor = m_buffer;
m_bufferFull = true;
// This function can only be used when the buffer is not yet full,
// and when then count is small enough to fit in the buffer.
// No need for a more general version for the search algorithm.
-void CircularSearchBuffer::append(int count, const QChar *characters)
+void CircularSearchBuffer::append(int count, const UChar* characters)
{
int tailSpace = m_buffer + length() - m_cursor;
if (m_isCaseSensitive) {
for (int i = 0; i != count; ++i) {
- QChar c = characters[i];
- m_cursor[i] = c.unicode() == nonBreakingSpace ? ' ' : c.unicode();
+ UChar c = characters[i];
+ m_cursor[i] = c == nonBreakingSpace ? ' ' : c;
}
} else {
for (int i = 0; i != count; ++i) {
- QChar c = characters[i];
- m_cursor[i] = c.unicode() == nonBreakingSpace ? ' ' : c.lower().unicode();
+ UChar c = characters[i];
+ m_cursor[i] = c == nonBreakingSpace ? ' ' : u_foldCase(c, U_FOLD_CASE_DEFAULT);
}
}
if (count < tailSpace)
int headSpace = m_cursor - m_buffer;
int tailSpace = length() - headSpace;
- return memcmp(m_cursor, m_target.unicode(), tailSpace * sizeof(QChar)) == 0
- && memcmp(m_buffer, m_target.unicode() + tailSpace, headSpace * sizeof(QChar)) == 0;
+ return memcmp(m_cursor, m_target.characters(), tailSpace * sizeof(UChar)) == 0
+ && memcmp(m_buffer, m_target.characters() + tailSpace, headSpace * sizeof(UChar)) == 0;
}
int TextIterator::rangeLength(const Range *r)
return resultRange.release();
}
-DeprecatedString plainText(const Range *r)
+DeprecatedString plainText(const Range* r)
{
DeprecatedString result("");
- for (TextIterator it(r); !it.atEnd(); it.advance()) {
- result.append(it.characters(), it.length());
- }
+ for (TextIterator it(r); !it.atEnd(); it.advance())
+ result.append(reinterpret_cast<const QChar*>(it.characters()), it.length());
return result;
}
/*
- * Copyright (C) 2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
// FIXME: Can't really answer this question correctly without knowing the white-space mode.
// FIXME: Move this along with the white-space position functions above
// somewhere else in the editing directory. It doesn't belong here.
-inline bool isCollapsibleWhitespace(const QChar& c)
+inline bool isCollapsibleWhitespace(UChar c)
{
- switch (c.unicode()) {
+ switch (c) {
case ' ':
case '\n':
return true;
void advance();
int length() const { return m_textLength; }
- const QChar *characters() const { return m_textCharacters; }
+ const UChar* characters() const { return m_textCharacters; }
PassRefPtr<Range> range() const;
bool handleReplacedElement();
bool handleNonTextNode();
void handleTextBox();
- void emitCharacter(QChar, Node *textNode, Node *offsetBaseNode, int textStartOffset, int textEndOffset);
+ void emitCharacter(UChar, Node *textNode, Node *offsetBaseNode, int textStartOffset, int textEndOffset);
// Current position, not necessarily of the text being returned, but position
// as we walk through the DOM tree.
mutable Node *m_positionOffsetBaseNode;
mutable int m_positionStartOffset;
mutable int m_positionEndOffset;
- const QChar *m_textCharacters;
+ const UChar* m_textCharacters;
int m_textLength;
// Used when there is still some pending text from the current node; when these
// Used to do the whitespace collapsing logic.
Node *m_lastTextNode;
bool m_lastTextNodeEndedWithCollapsedSpace;
- QChar m_lastCharacter;
+ UChar m_lastCharacter;
// Used for whitespace characters that aren't in the DOM, so we can point at them.
- QChar m_singleCharacterBuffer;
+ UChar m_singleCharacterBuffer;
// Used when text boxes are out of order (Hebrew/Arabic w/ embeded LTR text)
Vector<InlineTextBox*> m_sortedTextBoxes;
void advance();
int length() const { return m_textLength; }
- const QChar *characters() const { return m_textCharacters; }
+ const UChar* characters() const { return m_textCharacters; }
PassRefPtr<Range> range() const;
bool handleTextNode();
bool handleReplacedElement();
bool handleNonTextNode();
- void emitCharacter(QChar, Node *Node, int startOffset, int endOffset);
+ void emitCharacter(UChar, Node *Node, int startOffset, int endOffset);
void emitNewline();
// Current position, not necessarily of the text being returned, but position
// as we walk through the DOM tree.
- Node *m_node;
+ Node* m_node;
int m_offset;
bool m_handledNode;
bool m_handledChildren;
// End of the range.
- Node *m_startNode;
+ Node* m_startNode;
int m_startOffset;
// The current text and its position, in the form to be returned from the iterator.
- Node *m_positionNode;
+ Node* m_positionNode;
int m_positionStartOffset;
int m_positionEndOffset;
- const QChar *m_textCharacters;
+ const UChar* m_textCharacters;
int m_textLength;
// Used to do the whitespace logic.
- Node *m_lastTextNode;
- QChar m_lastCharacter;
+ Node* m_lastTextNode;
+ UChar m_lastCharacter;
// Used for whitespace characters that aren't in the DOM, so we can point at them.
- QChar m_singleCharacterBuffer;
+ UChar m_singleCharacterBuffer;
};
// Builds on the text iterator, adding a character position so we can walk one
bool atEnd() const { return m_textIterator.atEnd(); }
int length() const { return m_textIterator.length() - m_runOffset; }
- const QChar *characters() const { return m_textIterator.characters() + m_runOffset; }
+ const UChar* characters() const { return m_textIterator.characters() + m_runOffset; }
DeprecatedString string(int numChars);
int characterOffset() const { return m_offset; }
void advance();
int length() const;
- const QChar *characters() const;
+ const UChar* characters() const;
// Range of the text we're currently returning
PassRefPtr<Range> range() const { return m_range; }
private:
// text from the previous chunk from the textIterator
- const QChar *m_previousText;
+ const UChar* m_previousText;
int m_previousLength;
// many chunks from textIterator concatenated
return node->offsetInCharacters() ? (int)static_cast<const CharacterData *>(node)->length() : (int)node->childNodeCount();
}
-QChar VisiblePosition::characterAfter() const
+UChar VisiblePosition::characterAfter() const
{
// We canonicalize to the first of two equivalent candidates, but the second of the two candidates
// is the one that will be inside the text node containing the character after this visible position.
Position pos = m_deepPosition.downstream();
- Node *node = pos.node();
- if (!node || !node->isTextNode()) {
- return QChar();
- }
- Text *textNode = static_cast<Text *>(pos.node());
+ Node* node = pos.node();
+ if (!node || !node->isTextNode())
+ return 0;
+ Text* textNode = static_cast<Text*>(pos.node());
int offset = pos.offset();
- if ((unsigned)offset >= textNode->length()) {
- return QChar();
- }
+ if ((unsigned)offset >= textNode->length())
+ return 0;
return textNode->data()[offset];
}
bool isLastInBlock() const;
- QChar characterAfter() const;
+ UChar characterAfter() const;
void debugPosition(const char* msg = "") const;
unsigned len = in.length();
for (unsigned i = 0; i < len; ++i) {
- switch (in[i].latin1()) {
+ switch (in[i].unicode()) {
case '&':
s += "&";
break;
using namespace HTMLNames;
-static VisiblePosition previousBoundary(const VisiblePosition &c, unsigned (*searchFunction)(const QChar *, unsigned))
+static VisiblePosition previousBoundary(const VisiblePosition &c, unsigned (*searchFunction)(const UChar *, unsigned))
{
Position pos = c.deepEquivalent();
Node *n = pos.node();
unsigned next = 0;
while (!it.atEnd() && it.length() > 0) {
// iterate to get chunks until the searchFunction returns a non-zero value.
- string.prepend(it.characters(), it.length());
- next = searchFunction(string.unicode(), string.length());
+ string.prepend(reinterpret_cast<const QChar*>(it.characters()), it.length());
+ next = searchFunction(reinterpret_cast<const UChar*>(string.unicode()), string.length());
if (next != 0)
break;
it.advance();
chars[0] = 'X';
chars[1] = ' ';
string.prepend(chars, 2);
- unsigned pastImage = searchFunction(string.unicode(), string.length());
+ unsigned pastImage = searchFunction(reinterpret_cast<const UChar*>(string.unicode()), string.length());
RefPtr<Range> range(it.range());
if (pastImage == 0)
pos = Position(range->startContainer(exception), range->startOffset(exception));
return VisiblePosition(pos, DOWNSTREAM);
}
-static VisiblePosition nextBoundary(const VisiblePosition &c, unsigned (*searchFunction)(const QChar *, unsigned))
+static VisiblePosition nextBoundary(const VisiblePosition &c, unsigned (*searchFunction)(const UChar *, unsigned))
{
Position pos = c.deepEquivalent();
Node *n = pos.node();
while (!it.atEnd() && it.length() > 0) {
// Keep asking the iterator for chunks until the search function
// returns an end value not equal to the length of the string passed to it.
- string.append(it.characters(), it.length());
- next = searchFunction(string.unicode(), string.length());
+ string.append(reinterpret_cast<const QChar*>(it.characters()), it.length());
+ next = searchFunction(reinterpret_cast<const UChar*>(string.unicode()), string.length());
if (next != string.length())
break;
it.advance();
chars[0] = ' ';
chars[1] = 'X';
string.append(chars, 2);
- unsigned pastImage = searchFunction(string.unicode(), string.length());
+ unsigned pastImage = searchFunction(reinterpret_cast<const UChar*>(string.unicode()), string.length());
RefPtr<Range> range(it.range());
int exception = 0;
if (next != pastImage)
// ---------
-static unsigned startWordBoundary(const QChar *characters, unsigned length)
+static unsigned startWordBoundary(const UChar* characters, unsigned length)
{
int start, end;
findWordBoundary(characters, length, length, &start, &end);
return previousBoundary(p, startWordBoundary);
}
-static unsigned endWordBoundary(const QChar *characters, unsigned length)
+static unsigned endWordBoundary(const UChar* characters, unsigned length)
{
int start, end;
findWordBoundary(characters, length, 0, &start, &end);
return nextBoundary(p, endWordBoundary);
}
-static unsigned previousWordPositionBoundary(const QChar *characters, unsigned length)
+static unsigned previousWordPositionBoundary(const UChar* characters, unsigned length)
{
return findNextWordFromIndex(characters, length, length, false);
}
return previousBoundary(c, previousWordPositionBoundary);
}
-static unsigned nextWordPositionBoundary(const QChar *characters, unsigned length)
+static unsigned nextWordPositionBoundary(const UChar* characters, unsigned length)
{
return findNextWordFromIndex(characters, length, 0, true);
}
// ---------
-static unsigned startSentenceBoundary(const QChar *characters, unsigned length)
+static unsigned startSentenceBoundary(const UChar* characters, unsigned length)
{
int start, end;
findSentenceBoundary(characters, length, length, &start, &end);
return previousBoundary(c, startSentenceBoundary);
}
-static unsigned endSentenceBoundary(const QChar *characters, unsigned length)
+static unsigned endSentenceBoundary(const UChar* characters, unsigned length)
{
int start, end;
findSentenceBoundary(characters, length, 0, &start, &end);
return nextBoundary(c, endSentenceBoundary);
}
-static unsigned previousSentencePositionBoundary(const QChar *characters, unsigned length)
+static unsigned previousSentencePositionBoundary(const UChar* characters, unsigned length)
{
return findNextSentenceFromIndex(characters, length, length, false);
}
return previousBoundary(c, previousSentencePositionBoundary);
}
-static unsigned nextSentencePositionBoundary(const QChar *characters, unsigned length)
+static unsigned nextSentencePositionBoundary(const UChar* characters, unsigned length)
{
return findNextSentenceFromIndex(characters, length, 0, true);
}
break;
if (r->isText()) {
if (style->preserveNewline()) {
- const QChar* text = static_cast<RenderText*>(r)->text();
+ const UChar* text = static_cast<RenderText*>(r)->text();
int i = static_cast<RenderText*>(r)->length();
int o = offset;
if (n == startNode && o < i)
if (r->isText() && r->caretMaxRenderedOffset() > 0) {
int length = static_cast<RenderText *>(r)->length();
if (style->preserveNewline()) {
- const QChar* text = static_cast<RenderText *>(r)->text();
+ const UChar* text = static_cast<RenderText *>(r)->text();
int o = n == startNode ? offset : 0;
for (int i = o; i < length; ++i)
if (text[i] == '\n')
StringImpl* s = proposedValue.impl();
int newLen = numCharactersInGraphemeClusters(s, maxLen);
for (int i = 0; i < newLen; ++i)
- if ((*s)[i].unicode() < ' ') {
+ if ((*s)[i] < ' ') {
newLen = i;
break;
}
using namespace HTMLNames;
+const UChar nonBreakingSpace = 0xa0;
+
/**
* @internal
*/
return false;
StringImpl *i = t->string();
unsigned int pos = 0;
- while (pos < i->length() && ((*i)[pos] == ' ' || (*i)[pos] == QChar(0xa0)))
+ while (pos < i->length() && ((*i)[pos] == ' ' || (*i)[pos] == nonBreakingSpace))
pos++;
if (pos == i->length())
possiblyMoveStrayContent = false;
static const char textareaEnd [] = "</textarea";
static const char titleEnd [] = "</title";
-#define KHTML_ALLOC_QCHAR_VEC( N ) (QChar*) fastMalloc( sizeof(QChar)*( N ) )
-#define KHTML_DELETE_QCHAR_VEC( P ) fastFree((char*)( P ))
-
// Full support for MS Windows extensions to Latin-1.
// Technically these extensions should only be activated for pages
// marked "windows-1252" or "cp1252", but
// We only need this for entities. For non-entity text, we handle this in the text encoding.
-static const unsigned short windowsLatin1ExtensionArray[32] = {
+static const UChar windowsLatin1ExtensionArray[32] = {
0x20AC, 0x0081, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, // 80-87
0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x008D, 0x017D, 0x008F, // 88-8F
0x0090, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, // 90-97
0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x009D, 0x017E, 0x0178 // 98-9F
};
-static inline QChar fixUpChar(QChar c)
+static inline UChar fixUpChar(UChar c)
{
- unsigned short code = c.unicode();
- if ((code & ~0x1F) != 0x0080)
+ if ((c & ~0x1F) != 0x0080)
return c;
- return windowsLatin1ExtensionArray[code - 0x80];
+ return windowsLatin1ExtensionArray[c - 0x80];
}
-inline bool tagMatch(const char *s1, const QChar *s2, unsigned length)
+static inline bool tagMatch(const char* s1, const UChar* s2, unsigned length)
{
for (unsigned i = 0; i != length; ++i) {
- char c1 = s1[i];
- char uc1 = toupper(c1);
- QChar c2 = s2[i];
+ unsigned char c1 = s1[i];
+ unsigned char uc1 = toupper(c1);
+ UChar c2 = s2[i];
if (c1 != c2 && uc1 != c2)
return false;
}
return true;
}
-void Token::addAttribute(Document* doc, const AtomicString& attrName, const AtomicString& v)
+inline void Token::addAttribute(Document* doc, const AtomicString& attrName, const AtomicString& v)
{
- Attribute* a = 0;
if (!attrName.isEmpty() && attrName != "/") {
- a = new MappedAttribute(attrName, v);
+ Attribute* a = new MappedAttribute(attrName, v);
if (!attrs)
attrs = new NamedMappedAttrMap(0);
attrs->insertAttribute(a);
cs->deref(this);
}
- if (buffer)
- KHTML_DELETE_QCHAR_VEC(buffer);
+ fastFree(buffer);
buffer = dest = 0;
size = 0;
- if (scriptCode)
- KHTML_DELETE_QCHAR_VEC(scriptCode);
+ fastFree(scriptCode);
scriptCode = 0;
scriptCodeSize = scriptCodeMaxSize = scriptCodeResync = 0;
m_state.setLoadingExtScript(false);
reset();
size = 254;
- buffer = KHTML_ALLOC_QCHAR_VEC( 255 );
+ buffer = static_cast<UChar*>(fastMalloc(sizeof(UChar) * 254));
dest = buffer;
tquote = NoQuote;
searchCount = 0;
while ( !src.isEmpty() ) {
checkScriptBuffer();
- unsigned char ch = src->latin1();
+ UChar ch = *src;
if (!scriptCodeResync && !brokenComments && !state.inTextArea() && !state.inXmp() && !state.inTitle() && ch == '-' && scriptCodeSize >= 3 && !src.escaped() && scriptCode[scriptCodeSize-3] == '<' && scriptCode[scriptCodeSize-2] == '!' && scriptCode[scriptCodeSize-1] == '-') {
state.setInComment(true);
state = parseComment(src, state);
continue;
}
- if ( scriptCodeResync && !tquote && ( ch == '>' ) ) {
+ if (scriptCodeResync && !tquote && ch == '>') {
++src;
scriptCodeSize = scriptCodeResync-1;
scriptCodeResync = 0;
return state;
}
// possible end of tagname, lets check.
- if ( !scriptCodeResync && !state.escaped() && !src.escaped() && ( ch == '>' || ch == '/' || ch <= ' ' ) && ch &&
+ if (!scriptCodeResync && !state.escaped() && !src.escaped() && (ch == '>' || ch == '/' || ch <= ' ') && ch &&
scriptCodeSize >= searchStopperLen &&
tagMatch( searchStopper, scriptCode+scriptCodeSize-searchStopperLen, searchStopperLen )) {
scriptCodeResync = scriptCodeSize-searchStopperLen+1;
tquote = NoQuote;
continue;
}
- if ( scriptCodeResync && !state.escaped() ) {
- if(ch == '\"')
+ if (scriptCodeResync && !state.escaped()) {
+ if (ch == '\"')
tquote = (tquote == NoQuote) ? DoubleQuote : ((tquote == SingleQuote) ? SingleQuote : NoQuote);
- else if(ch == '\'')
+ else if (ch == '\'')
tquote = (tquote == NoQuote) ? SingleQuote : (tquote == DoubleQuote) ? DoubleQuote : NoQuote;
else if (tquote != NoQuote && (ch == '\r' || ch == '\n'))
tquote = NoQuote;
}
state.setEscaped(!state.escaped() && ch == '\\');
if (!scriptCodeResync && (state.inTextArea() || state.inTitle()) && !src.escaped() && ch == '&') {
- QChar *scriptCodeDest = scriptCode+scriptCodeSize;
+ UChar* scriptCodeDest = scriptCode+scriptCodeSize;
++src;
state = parseEntity(src, scriptCodeDest, state, m_cBufferPos, true, false);
scriptCodeSize = scriptCodeDest-scriptCode;
- }
- else {
+ } else {
scriptCode[scriptCodeSize++] = *src;
++src;
}
doScriptExec = true;
}
state = processListing(SegmentedString(scriptCode, scriptCodeSize), state);
- DeprecatedString exScript( buffer, dest-buffer );
+ DeprecatedString exScript(reinterpret_cast<QChar*>(buffer), dest - buffer);
processToken();
currToken.tagName = scriptTag.localName();
currToken.beginTag = false;
checkScriptBuffer(src.length());
while ( !src.isEmpty() ) {
scriptCode[ scriptCodeSize++ ] = *src;
-#if defined(TOKEN_DEBUG) && TOKEN_DEBUG > 1
- qDebug("comment is now: *%s*",
- QConstString((QChar*)src.operator->(), min(16U, src.length())).string().latin1());
-#endif
- if (src->unicode() == '>') {
+ if (*src == '>') {
bool handleBrokenComments = brokenComments && !(state.inScript() || state.inStyle());
int endCharsCount = 1; // start off with one for the '>' character
if (scriptCodeSize > 2 && scriptCode[scriptCodeSize-3] == '-' && scriptCode[scriptCodeSize-2] == '-') {
checkScriptBuffer(src.length());
while (!src.isEmpty()) {
scriptCode[scriptCodeSize++] = *src;
- if (src->unicode() == '>' &&
+ if (*src == '>' &&
scriptCodeSize > 1 && scriptCode[scriptCodeSize-2] == '%') {
++src;
state.setInServer(false);
HTMLTokenizer::State HTMLTokenizer::parseProcessingInstruction(SegmentedString &src, State state)
{
- char oldchar = 0;
- while ( !src.isEmpty() )
- {
- unsigned char chbegin = src->latin1();
- if(chbegin == '\'') {
+ UChar oldchar = 0;
+ while (!src.isEmpty()) {
+ UChar chbegin = *src;
+ if (chbegin == '\'')
tquote = tquote == SingleQuote ? NoQuote : SingleQuote;
- }
- else if(chbegin == '\"') {
+ else if (chbegin == '\"')
tquote = tquote == DoubleQuote ? NoQuote : DoubleQuote;
- }
// Look for '?>'
- // some crappy sites omit the "?" before it, so
+ // Some crappy sites omit the "?" before it, so
// we look for an unquoted '>' instead. (IE compatible)
- else if ( chbegin == '>' && ( !tquote || oldchar == '?' ) )
- {
+ else if (chbegin == '>' && (!tquote || oldchar == '?')) {
// We got a '?>' sequence
state.setInProcessingInstruction(false);
++src;
HTMLTokenizer::State HTMLTokenizer::parseText(SegmentedString &src, State state)
{
while (!src.isEmpty()) {
- unsigned short cc = src->unicode();
+ UChar cc = *src;
if (state.skipLF()) {
state.setSkipLF(false);
}
-HTMLTokenizer::State HTMLTokenizer::parseEntity(SegmentedString &src, QChar *&dest, State state, unsigned &cBufferPos, bool start, bool parsingTag)
+HTMLTokenizer::State HTMLTokenizer::parseEntity(SegmentedString &src, UChar*& dest, State state, unsigned &cBufferPos, bool start, bool parsingTag)
{
if (start)
{
while(!src.isEmpty())
{
- unsigned short cc = src->unicode();
+ UChar cc = *src;
switch(state.entityState()) {
case NoEntity:
ASSERT(state.entityState() != NoEntity);
break;
case NumericSearch:
- if(cc == 'x' || cc == 'X') {
+ if (cc == 'x' || cc == 'X') {
cBuffer[cBufferPos++] = cc;
++src;
state.setEntityState(Hexadecimal);
- }
- else if(cc >= '0' && cc <= '9')
+ } else if (cc >= '0' && cc <= '9')
state.setEntityState(Decimal);
else
state.setEntityState(SearchSemicolon);
-
break;
- case Hexadecimal:
- {
- int ll = min(src.length(), 10-cBufferPos);
- while(ll--) {
- QChar csrc(src->lower());
- cc = csrc.unicode();
-
- if (!((cc >= '0' && cc <= '9') || (cc >= 'a' && cc <= 'f'))) {
+ case Hexadecimal: {
+ int ll = min(src.length(), 10 - cBufferPos);
+ while (ll--) {
+ cc = *src;
+ if (!((cc >= '0' && cc <= '9') || (cc >= 'a' && cc <= 'f') || (cc >= 'A' && cc <= 'F'))) {
state.setEntityState(SearchSemicolon);
break;
}
- EntityUnicodeValue = EntityUnicodeValue*16 + (cc - ( cc < 'a' ? '0' : 'a' - 10));
+ int digit;
+ if (cc < 'A')
+ digit = cc - '0';
+ else
+ digit = (cc - 'A' + 10) & 0xF; // handle both upper and lower case without a branch
+ EntityUnicodeValue = EntityUnicodeValue * 16 + digit;
cBuffer[cBufferPos++] = cc;
++src;
}
{
int ll = min(src.length(), 9-cBufferPos);
while(ll--) {
- cc = src->unicode();
+ cc = *src;
if (!(cc >= '0' && cc <= '9')) {
state.setEntityState(SearchSemicolon);
{
int ll = min(src.length(), 9-cBufferPos);
while(ll--) {
- QChar csrc = *src;
- cc = csrc.unicode();
+ cc = *src;
if (!((cc >= 'a' && cc <= 'z') || (cc >= '0' && cc <= '9') || (cc >= 'A' && cc <= 'Z'))) {
state.setEntityState(SearchSemicolon);
}
case SearchSemicolon:
// Don't allow values that are more than 21 bits.
- if (EntityUnicodeValue > 0 && EntityUnicodeValue <= 0x1FFFFF) {
-
+ if (EntityUnicodeValue > 0 && EntityUnicodeValue <= 0x10FFFF) {
if (*src == ';')
++src;
-
if (EntityUnicodeValue <= 0xFFFF) {
checkBuffer();
src.push(fixUpChar(EntityUnicodeValue));
} else {
// Convert to UTF-16, using surrogate code points.
- QChar c1(0xD800 | (((EntityUnicodeValue >> 16) - 1) << 6) | ((EntityUnicodeValue >> 10) & 0x3F));
- QChar c2(0xDC00 | (EntityUnicodeValue & 0x3FF));
checkBuffer(2);
- src.push(c1);
- src.push(c2);
+ src.push(U16_LEAD(EntityUnicodeValue));
+ src.push(U16_TRAIL(EntityUnicodeValue));
}
} else {
checkBuffer(10);
while (!src.isEmpty())
{
checkBuffer();
-#if defined(TOKEN_DEBUG) && TOKEN_DEBUG > 1
- unsigned l = 0;
- while(l < src.length() && (*(src.operator->()+l)).latin1() != '>')
- l++;
- qDebug("src is now: *%s*, tquote: %d",
- QConstString((QChar*)src.operator->(), l).deprecatedString().latin1(), tquote);
-#endif
switch(state.tagState()) {
case NoTag:
{
++src;
if (!src.isEmpty())
// cuts off high bits, which is okay
- cBuffer[cBufferPos++] = src->unicode();
+ cBuffer[cBufferPos++] = *src;
}
else
state = parseComment(src, state);
return state; // Finished parsing tag!
}
// cuts off high bits, which is okay
- cBuffer[cBufferPos++] = src->unicode();
+ cBuffer[cBufferPos++] = *src;
++src;
break;
}
bool finish = false;
unsigned int ll = min(src.length(), CBUFLEN-cBufferPos);
while(ll--) {
- unsigned short curchar = src->unicode();
+ UChar curchar = *src;
if(curchar <= ' ' || curchar == '>' ) {
finish = true;
break;
qDebug("SearchAttribute");
#endif
while(!src.isEmpty()) {
- unsigned short curchar = src->unicode();
+ UChar curchar = *src;
// In this mode just ignore any quotes we encounter and treat them like spaces.
if (curchar > ' ' && curchar != '\'' && curchar != '"') {
if (curchar == '<' || curchar == '>')
#endif
int ll = min(src.length(), CBUFLEN-cBufferPos);
while(ll--) {
- unsigned short curchar = src->unicode();
+ UChar curchar = *src;
if (curchar <= '>' && (curchar >= '=' || curchar <= ' ')) {
cBuffer[cBufferPos] = '\0';
attrName = AtomicString(cBuffer);
qDebug("SearchEqual");
#endif
while(!src.isEmpty()) {
- unsigned short curchar = src->unicode();
+ UChar curchar = *src;
// In this mode just ignore any quotes we encounter and treat them like spaces.
if (curchar > ' ' && curchar != '\'' && curchar != '"') {
if(curchar == '=') {
break;
case SearchValue:
while(!src.isEmpty()) {
- unsigned short curchar = src->unicode();
+ UChar curchar = *src;
if(curchar > ' ') {
if(( curchar == '\'' || curchar == '\"' )) {
tquote = curchar == '\"' ? DoubleQuote : SingleQuote;
while(!src.isEmpty()) {
checkBuffer();
- unsigned short curchar = src->unicode();
+ UChar curchar = *src;
if (curchar == '>' && attrName.isEmpty()) {
// Handle a case like <img '>. Just go ahead and be willing
// to close the whole tag. Don't consume the character and
#endif
while(!src.isEmpty()) {
checkBuffer();
- unsigned short curchar = src->unicode();
+ UChar curchar = *src;
if(curchar <= '>' && !src.escaped()) {
// parse Entities
if ( curchar == '&' )
// do we need to enlarge the buffer?
checkBuffer();
- unsigned short cc = src->unicode();
+ UChar cc = *src;
bool wasSkipLF = state.skipLF();
if (wasSkipLF)
if (!m_state.hasTagState())
processToken();
- if (scriptCode)
- KHTML_DELETE_QCHAR_VEC(scriptCode);
+ fastFree(scriptCode);
scriptCode = 0;
scriptCodeSize = scriptCodeMaxSize = scriptCodeResync = 0;
- KHTML_DELETE_QCHAR_VEC(buffer);
+ fastFree(buffer);
buffer = 0;
}
int pos;
DeprecatedString food;
if (m_state.inScript() || m_state.inStyle())
- food.setUnicode(scriptCode, scriptCodeSize);
+ food.setUnicode(reinterpret_cast<QChar*>(scriptCode), scriptCodeSize);
else if (m_state.inServer()) {
food = "<";
- food += DeprecatedString(scriptCode, scriptCodeSize);
+ food += DeprecatedString(reinterpret_cast<QChar*>(scriptCode), scriptCodeSize);
} else {
- pos = QConstString(scriptCode, scriptCodeSize).string().find('>');
- food.setUnicode(scriptCode+pos+1, scriptCodeSize-pos-1); // deep copy
+ pos = QConstString(reinterpret_cast<QChar*>(scriptCode), scriptCodeSize).string().find('>');
+ food.setUnicode(reinterpret_cast<QChar*>(scriptCode) + pos + 1, scriptCodeSize - pos - 1); // deep copy
}
- KHTML_DELETE_QCHAR_VEC(scriptCode);
+ fastFree(scriptCode);
scriptCode = 0;
scriptCodeSize = scriptCodeMaxSize = scriptCodeResync = 0;
m_state.setInComment(false);
void HTMLTokenizer::enlargeBuffer(int len)
{
- int newsize = max(size*2, size+len);
- int oldoffs = (dest - buffer);
-
- buffer = (QChar*)fastRealloc(buffer, newsize*sizeof(QChar));
- dest = buffer + oldoffs;
- size = newsize;
+ int newSize = max(size * 2, size + len);
+ int oldOffset = dest - buffer;
+ buffer = static_cast<UChar*>(fastRealloc(buffer, newSize * sizeof(UChar)));
+ dest = buffer + oldOffset;
+ size = newSize;
}
void HTMLTokenizer::enlargeScriptBuffer(int len)
{
- int newsize = max(scriptCodeMaxSize*2, scriptCodeMaxSize+len);
- scriptCode = (QChar*)fastRealloc(scriptCode, newsize*sizeof(QChar));
- scriptCodeMaxSize = newsize;
+ int newSize = max(scriptCodeMaxSize * 2, scriptCodeMaxSize + len);
+ scriptCode = static_cast<UChar*>(fastRealloc(scriptCode, newSize * sizeof(UChar)));
+ scriptCodeMaxSize = newSize;
}
-void HTMLTokenizer::notifyFinished(CachedObject */*finishedObj*/)
+void HTMLTokenizer::notifyFinished(CachedObject*)
{
#if INSTRUMENT_LAYOUT_SCHEDULING
if (!parser->doc()->ownerElement())
ASSERT(!tok.processingData()); // make sure we're done (see 3963151)
}
-unsigned short decodeNamedEntity(const char* name)
+UChar decodeNamedEntity(const char* name)
{
const Entity* e = findEntity(name, strlen(name));
return e ? e->code : 0;
HTMLTokenizer(DocumentFragment*);
virtual ~HTMLTokenizer();
- virtual bool write(const SegmentedString &str, bool appendData);
+ virtual bool write(const SegmentedString&, bool appendData);
virtual void finish();
virtual void setForceSynchronous(bool force);
virtual bool isWaitingForScripts() const;
State parseText(SegmentedString&, State);
State parseSpecial(SegmentedString&, State);
State parseTag(SegmentedString&, State);
- State parseEntity(SegmentedString &, QChar*& dest, State, unsigned& _cBufferPos, bool start, bool parsingTag);
+ State parseEntity(SegmentedString&, UChar*& dest, State, unsigned& _cBufferPos, bool start, bool parsingTag);
State parseProcessingInstruction(SegmentedString&, State);
State scriptHandler(State);
State scriptExecution(const DeprecatedString& script, State state, DeprecatedString scriptURL = DeprecatedString(), int baseLine = 0);
- void setSrc(const SegmentedString &source);
+ void setSrc(const SegmentedString&);
// check if we have enough space in the buffer.
// if not enlarge it
void enlargeBuffer(int len);
void enlargeScriptBuffer(int len);
- bool continueProcessing(int& processedCount, double startTime, State &state);
+ bool continueProcessing(int& processedCount, double startTime, State&);
void timerFired(Timer<HTMLTokenizer>*);
void allDataProcessed();
// Internal buffers
///////////////////
- QChar *buffer;
- QChar *dest;
+ UChar* buffer;
+ UChar* dest;
Token currToken;
// Tokenizer flags
//////////////////
// are we in quotes within a html tag
- enum
- {
- NoQuote = 0,
- SingleQuote,
- DoubleQuote
- } tquote;
+ enum { NoQuote, SingleQuote, DoubleQuote } tquote;
// Are we in a &... character entity description?
enum EntityState {
AtomicString attrName;
// Used to store the code of a srcipting sequence
- QChar *scriptCode;
+ UChar* scriptCode;
// Size of the script sequenze stored in @ref #scriptCode
int scriptCodeSize;
// Maximal size that can be stored in @ref #scriptCode
int scriptCodeResync;
// Stores characters if we are scanning for a string like "</script>"
- QChar searchBuffer[ 10 ];
+ UChar searchBuffer[10];
// Counts where we are in the string we are scanning for
int searchCount;
// The string we are searching for
- const QChar *searchFor;
+ const UChar* searchFor;
// the stopper string
const char* searchStopper;
// the stopper len
void parseHTMLDocumentFragment(const String&, DocumentFragment*);
-unsigned short decodeNamedEntity(const char*);
+UChar decodeNamedEntity(const char*);
}
// Allows leading spaces.
// Allows trailing nonnumeric characters.
// Returns 10 for any size greater than 9.
-static bool parseFontSizeNumber(const String &s, int &size)
+static bool parseFontSizeNumber(const String& s, int& size)
{
unsigned pos = 0;
// Skip leading spaces.
- while (pos < s.length() && s[pos].isSpace())
+ while (QChar(s[pos]).isSpace())
++pos;
// Skip a plus or minus.
bool sawPlus = false;
bool sawMinus = false;
- if (pos < s.length() && s[pos] == '+') {
+ if (s[pos] == '+') {
++pos;
sawPlus = true;
- } else if (pos < s.length() && s[pos] == '-') {
+ } else if (s[pos] == '-') {
++pos;
sawMinus = true;
}
// Parse a single digit.
- if (pos >= s.length() || !s[pos].isNumber())
+ if (!u_isdigit(s[pos]))
return false;
- int num = s[pos++].digitValue();
+ int num = u_charDigitValue(s[pos++]);
// Check for an additional digit.
- if (pos < s.length() && s[pos].isNumber())
+ if (u_isdigit(s[pos]))
num = 10;
if (sawPlus) {
#import "config.h"
#import "KWQLoader.h"
+#import "BlockExceptions.h"
#import "Cache.h"
#import "CachedImage.h"
#import "DocLoader.h"
#import "FoundationExtras.h"
-#import "BlockExceptions.h"
+#import "FrameMac.h"
#import "KWQFormData.h"
-#import "TransferJob.h"
-#import "Logging.h"
#import "KWQResourceLoader.h"
-#import "FrameMac.h"
+#import "Logging.h"
#import "Request.h"
+#import "TransferJob.h"
#import "WebCoreFrameBridge.h"
#import "loader.h"
-#import "loader.h"
-
#import <Foundation/NSURLResponse.h>
using namespace WebCore;
}
}
-#define LOCAL_STRING_BUFFER_SIZE 1024
-
-bool KWQIsResponseURLEqualToURL(NSURLResponse *response, const WebCore::String &m_url)
+bool KWQIsResponseURLEqualToURL(NSURLResponse *response, const WebCore::String& m_url)
{
- unichar _buffer[LOCAL_STRING_BUFFER_SIZE];
- unichar *urlStringCharacters;
-
NSURL *responseURL = [(NSURLResponse *)response URL];
NSString *urlString = [responseURL absoluteString];
- if (m_url.length() != [urlString length])
+ size_t length = m_url.length();
+ if (length != [urlString length])
return false;
-
- // Nasty hack to directly compare strings buffers of NSString
- // and String. We do this for speed.
- if ([urlString length] > LOCAL_STRING_BUFFER_SIZE) {
- urlStringCharacters = (unichar *)fastMalloc(sizeof(unichar)*[urlString length]);
- }
- else {
- urlStringCharacters = _buffer;
- }
- [urlString getCharacters:urlStringCharacters];
-
- bool ret = false;
- if(!memcmp(urlStringCharacters, m_url.unicode(), m_url.length()*sizeof(QChar)))
- ret = true;
-
- if (urlStringCharacters != _buffer)
- fastFree(urlStringCharacters);
-
- return ret;
+
+ Vector<UChar, 1024> buffer(length);
+ [urlString getCharacters:buffer.data()];
+ return !memcmp(buffer.data(), m_url.characters(), length * sizeof(UChar));
}
DeprecatedString KWQResponseURL(NSURLResponse *response)
#include "config.h"
#include "KWQTextStream.h"
+#include "DeprecatedString.h"
#include "PlatformString.h"
#include "Logging.h"
return anchor->renderer()->document()->getAccObjectCache()->get(anchor->renderer());
}
-static void AXAttributedStringAppendText (NSMutableAttributedString *attrString, Node *nodeImpl, const QChar *chars, int length)
+static void AXAttributedStringAppendText(NSMutableAttributedString* attrString, Node* nodeImpl, const UChar* chars, int length)
{
// skip invisible text
if (!nodeImpl->renderer())
NSRange attrStringRange = NSMakeRange([attrString length], length);
// append the string from this node
- [[attrString mutableString] appendString:[NSString stringWithCharacters:(const UniChar*)chars length:length]];
+ [[attrString mutableString] appendString:[NSString stringWithCharacters:chars length:length]];
// add new attributes and remove irrelevant inherited ones
// NOTE: color attributes are handled specially because -[NSMutableAttributedString addAttribute: value: range:] does not merge
// non-zero length means textual node, zero length means replaced node (AKA "attachments" in AX)
if (it.length() != 0) {
- AXAttributedStringAppendText (attrString, nodeImpl, it.characters(), it.length());
+ AXAttributedStringAppendText(attrString, nodeImpl, it.characters(), it.length());
} else {
- AXAttributedStringAppendReplaced (attrString, nodeImpl->childNode(it.range()->startOffset(exception)));
+ AXAttributedStringAppendReplaced(attrString, nodeImpl->childNode(it.range()->startOffset(exception)));
}
it.advance();
return static_cast<CachedCSSStyleSheet *>(o);
}
-void Cache::preloadStyleSheet(const DeprecatedString& url, const DeprecatedString& stylesheet_data)
-{
- CachedObject *o = cache->get(String(url).impl());
- if (o)
- remove(o);
- cache->set(String(url).impl(), new CachedCSSStyleSheet(url, stylesheet_data));
-}
-
CachedScript *Cache::requestScript(DocLoader* dl, const String& url, bool reload, time_t expireDate, const DeprecatedString& charset)
{
// this brings the _url to a standard form...
return static_cast<CachedScript *>(o);
}
-void Cache::preloadScript(const DeprecatedString& url, const DeprecatedString& script_data)
-{
- CachedObject *o = cache->get(String(url).impl());
- if (o)
- remove(o);
- cache->set(String(url).impl(), new CachedScript(url, script_data));
-}
-
#ifdef KHTML_XSLT
CachedXSLStyleSheet* Cache::requestXSLStyleSheet(DocLoader* dl, const String& url, bool reload, time_t expireDate)
{
/**
* Provides a cache/loader for objects needed for displaying the html page.
- * At the moment these are stylesheets, scripts and images
*/
class Cache {
friend class DocLoader;
public:
/**
- * init the cache in case it's not already. This needs to get called once
- * before using it.
+ * Initialize the cache in case it's not already.
+ * This needs to get called once before using it.
*/
static void init();
/**
- * Ask the cache for some url. Will return a cachedObject, and
- * load the requested data in case it's not cahced
- * if the DocLoader is zero, the url must be full-qualified.
- * Otherwise, it is automatically base-url expanded
+ * Ask the cache for some URL.
+ * If the DocLoader is zero, the URL must be fully-qualified. Otherwise, it is automatically base-URL expanded
*/
static CachedImage* requestImage(DocLoader*, const String& URL, bool reload = false, time_t expireDate = 0);
- static CachedImage* requestImage(DocLoader*, const KURL& url, bool reload = false, time_t expireDate = 0);
-
- /**
- * Ask the cache for some url. Will return a cachedObject, and
- * load the requested data in case it's not cached
- */
- static CachedCSSStyleSheet* requestStyleSheet(DocLoader*, const String& URL, bool reload = false, time_t expireDate = 0, const DeprecatedString& charset = DeprecatedString::null);
-
- /**
- * Pre-loads a stylesheet into the cache.
- */
- static void preloadStyleSheet(const DeprecatedString &url, const DeprecatedString& stylesheetData);
-
- /**
- * Ask the cache for some url. Will return a cachedObject, and
- * load the requested data in case it's not cahced
- */
- static CachedScript* requestScript(DocLoader*, const String& URL, bool reload = false, time_t expireDate = 0, const DeprecatedString& charset = DeprecatedString::null);
-
- /**
- * Pre-loads a script into the cache.
- */
- static void preloadScript(const DeprecatedString &url, const DeprecatedString& scriptData);
+ static CachedImage* requestImage(DocLoader*, const KURL& URL, bool reload, time_t expireDate);
+ static CachedCSSStyleSheet* requestStyleSheet(DocLoader*, const String& URL, bool reload, time_t expireDate, const DeprecatedString& charset);
+ static CachedScript* requestScript(DocLoader*, const String& URL, bool reload, time_t expireDate, const DeprecatedString& charset);
#ifdef KHTML_XSLT
- // Ask the cache for an XSL stylesheet.
- static CachedXSLStyleSheet* requestXSLStyleSheet(DocLoader*, const String& URL, bool reload = false, time_t expireDate = 0);
+ static CachedXSLStyleSheet* requestXSLStyleSheet(DocLoader*, const String& URL, bool reload, time_t expireDate);
#endif
#ifndef KHTML_NO_XBL
- // Ask the cache for an XBL document.
- static CachedXBLDocument* requestXBLDocument(DocLoader*, const String& URL, bool reload = false, time_t expireDate = 0);
+ static CachedXBLDocument* requestXBLDocument(DocLoader*, const String& URL, bool reload, time_t expireDate);
#endif
/**
- * Sets the size of the cache. This will only hod approximately, since the size some
- * cached objects (like stylesheets) take up in memory is not exaclty known.
+ * Sets the size of the cache. This will only hold approximately, since the size some
+ * cached objects (like stylesheets) take up in memory is not exactly known.
*/
static void setSize(int bytes);
+
/**
* returns the size of the cache
*/
/**
* clears the cache
- * Warning: call this only at the end of your program, to clean
- * up memory (useful for finding memory holes)
+ * Warning: call this only at the end of your program, to clean up memory
+ * (useful for finding memory leaks).
*/
static void clear();
#ifndef KHTML_CachedObject_h
#define KHTML_CachedObject_h
+#include "DeprecatedString.h"
#include "PlatformString.h"
#include "KWQKIOGlobal.h"
#include <wtf/HashSet.h>
#endif
using namespace std;
-using namespace KJS;
+
+using KJS::JSLock;
+using KJS::JSValue;
+using KJS::Location;
+using KJS::PausedTimeouts;
+using KJS::SavedProperties;
+using KJS::SavedBuiltins;
+using KJS::UString;
+using KJS::Window;
namespace WebCore {
public:
UserStyleSheetLoader(Frame* frame, const String& url, DocLoader* dl)
: m_frame(frame)
- , m_cachedSheet(Cache::requestStyleSheet(dl, url))
+ , m_cachedSheet(Cache::requestStyleSheet(dl, url, false, 0, ""))
{
m_cachedSheet->ref(this);
}
doc->dispatchWindowEvent(flag ? focusEvent : blurEvent, false, false);
}
-QChar Frame::backslashAsCurrencySymbol() const
+UChar Frame::backslashAsCurrencySymbol() const
{
Document *doc = document();
if (!doc)
void setWindowHasFocus(bool flag);
// Convenience, to avoid repeating the code to dig down to get this.
- QChar backslashAsCurrencySymbol() const;
+ UChar backslashAsCurrencySymbol() const;
DeprecatedValueList<MarkedTextUnderline> markedTextUnderlines() const;
bool markedTextUsesUnderlines() const;
#include "config.h"
#if AVOID_STATIC_CONSTRUCTORS
-#define KHTML_ATOMICSTRING_HIDE_GLOBALS 1
+#define ATOMICSTRING_HIDE_GLOBALS 1
#endif
#include "AtomicString.h"
+#include "DeprecatedString.h"
#include "StaticConstructors.h"
#include "StringHash.h"
#include <kjs/identifier.h>
#include <wtf/HashSet.h>
-using namespace KJS;
+using KJS::Identifier;
+using KJS::UString;
namespace WebCore {
-
+
static HashSet<StringImpl*>* stringTable;
struct CStringTranslator
static bool equal(StringImpl* r, const char* s)
{
int length = r->length();
- const QChar* d = r->unicode();
+ const UChar* d = r->characters();
for (int i = 0; i != length; ++i)
if (d[i] != s[i])
return false;
bool operator==(const AtomicString& a, const char* b)
{
StringImpl* impl = a.impl();
- if ((!impl || !impl->unicode()) && !b)
+ if ((!impl || !impl->characters()) && !b)
return true;
- if ((!impl || !impl->unicode()) || !b)
+ if ((!impl || !impl->characters()) || !b)
return false;
return CStringTranslator::equal(impl, b);
}
return *stringTable->add<const char*, CStringTranslator>(c).first;
}
-struct QCharBuffer {
- const QChar* s;
+struct UCharBuffer {
+ const UChar* s;
unsigned length;
};
-struct QCharBufferTranslator {
- static unsigned hash(const QCharBuffer& buf)
+struct UCharBufferTranslator {
+ static unsigned hash(const UCharBuffer& buf)
{
return StringImpl::computeHash(buf.s, buf.length);
}
- static bool equal(StringImpl* const& str, const QCharBuffer& buf)
+ static bool equal(StringImpl* const& str, const UCharBuffer& buf)
{
unsigned strLength = str->length();
unsigned bufLength = buf.length;
if (strLength != bufLength)
return false;
- const uint32_t* strChars = reinterpret_cast<const uint32_t*>(str->unicode());
+ const uint32_t* strChars = reinterpret_cast<const uint32_t*>(str->characters());
const uint32_t* bufChars = reinterpret_cast<const uint32_t*>(buf.s);
unsigned halfLength = strLength >> 1;
return true;
}
- static void translate(StringImpl*& location, const QCharBuffer& buf, unsigned hash)
+ static void translate(StringImpl*& location, const UCharBuffer& buf, unsigned hash)
{
StringImpl *r = new StringImpl(buf.s, buf.length);
r->m_hash = hash;
}
};
-StringImpl* AtomicString::add(const QChar* s, int length)
+StringImpl* AtomicString::add(const UChar* s, int length)
{
if (!s)
return 0;
if (length == 0)
return StringImpl::empty();
- QCharBuffer buf = {s, length};
- return *stringTable->add<QCharBuffer, QCharBufferTranslator>(buf).first;
+ UCharBuffer buf = {s, length};
+ return *stringTable->add<UCharBuffer, UCharBufferTranslator>(buf).first;
}
StringImpl* AtomicString::add(StringImpl* r)
StringImpl* AtomicString::add(const KJS::Identifier& str)
{
- return add(reinterpret_cast<const QChar*>(str.data()), str.size());
+ return add(reinterpret_cast<const UChar*>(str.data()), str.size());
}
StringImpl* AtomicString::add(const KJS::UString& str)
{
- return add(reinterpret_cast<const QChar*>(str.data()), str.size());
+ return add(reinterpret_cast<const UChar*>(str.data()), str.size());
}
AtomicString::operator Identifier() const
{
- return domString();
+ return m_string;
}
AtomicString::operator UString() const
{
- return domString();
+ return m_string;
+}
+
+AtomicString::AtomicString(const DeprecatedString& s)
+ : m_string(add(reinterpret_cast<const UChar*>(s.unicode()), s.length()))
+{
+}
+
+DeprecatedString AtomicString::deprecatedString() const
+{
+ return m_string.deprecatedString();
}
DEFINE_GLOBAL(AtomicString, nullAtom)
static void init();
AtomicString() { }
- AtomicString(QChar c) : m_string(add(&c, 1)) { }
AtomicString(const char* s) : m_string(add(s)) { }
- AtomicString(const QChar* s, int length) : m_string(add(s, length)) { }
- AtomicString(const unsigned short* s, int length) : m_string(add((QChar*)s, length)) { }
- AtomicString(const DeprecatedString& s) : m_string(add(s.unicode(), s.length())) { }
+ AtomicString(const UChar* s, int length) : m_string(add(s, length)) { }
AtomicString(const KJS::UString& s) : m_string(add(s)) { }
AtomicString(const KJS::Identifier& s) : m_string(add(s)) { }
AtomicString(StringImpl* imp) : m_string(add(imp)) { }
AtomicString(AtomicStringImpl* imp) : m_string(imp) { }
AtomicString(const String& s) : m_string(add(s.impl())) { }
-
+
operator const String&() const { return m_string; }
const String& domString() const { return m_string; };
- DeprecatedString deprecatedString() const { return m_string.deprecatedString(); };
-
+
operator KJS::Identifier() const;
operator KJS::UString() const;
AtomicStringImpl* impl() const { return static_cast<AtomicStringImpl *>(m_string.impl()); }
- const QChar* unicode() const { return m_string.unicode(); }
+ const UChar* characters() const { return m_string.characters(); }
unsigned length() const { return m_string.length(); }
- const QChar& operator [](unsigned int i) const { return m_string[i]; }
+ UChar operator[](unsigned int i) const { return m_string[i]; }
- bool contains(QChar c) const { return m_string.contains(c); }
+ bool contains(UChar c) const { return m_string.contains(c); }
bool contains(const AtomicString& s, bool caseSensitive = true) const
{ return m_string.contains(s.domString(), caseSensitive); }
- int find(QChar c, int start = 0) const { return m_string.find(c, start); }
+ int find(UChar c, int start = 0) const { return m_string.find(c, start); }
int find(const AtomicString& s, int start = 0, bool caseSentitive = true) const
{ return m_string.find(s.domString(), start, caseSentitive); }
operator NSString*() const { return m_string; }
#endif
+ AtomicString(const DeprecatedString&);
+ DeprecatedString deprecatedString() const;
+
private:
String m_string;
static StringImpl* add(const char*);
- static StringImpl* add(const QChar*, int length);
+ static StringImpl* add(const UChar*, int length);
static StringImpl* add(StringImpl*);
static StringImpl* add(const KJS::UString&);
static StringImpl* add(const KJS::Identifier&);
inline bool equalIgnoringCase(const String& a, const AtomicString& b) { return equalIgnoringCase(a.impl(), b.impl()); }
// Define external global variables for the commonly used atomic strings.
-#if !KHTML_ATOMICSTRING_HIDE_GLOBALS
+#if !ATOMICSTRING_HIDE_GLOBALS
extern const AtomicString nullAtom;
extern const AtomicString emptyAtom;
extern const AtomicString textAtom;
#include "config.h"
#include "Color.h"
+#include "DeprecatedString.h"
#include "PlatformString.h"
#include <wtf/Assertions.h>
class QChar {
public:
-
- enum Direction {
- DirL = 0, DirR, DirEN, DirES, DirET, DirAN, DirCS, DirB, DirS, DirWS, DirON,
- DirLRE, DirLRO, DirAL, DirRLE, DirRLO, DirPDF, DirNSM, DirBN
- };
-
QChar();
QChar(char);
QChar(unsigned char);
unsigned short unicode() const;
char latin1() const;
bool isSpace() const;
- bool isDigit() const;
- bool isLetter() const;
- bool isNumber() const;
- bool isLetterOrNumber() const;
- bool isPunct() const;
- int digitValue() const;
QChar lower() const;
QChar upper() const;
- Direction direction() const;
private:
unsigned short c;
{
// Use isspace() for basic Latin-1.
// This will include newlines, which aren't included in unicode DirWS.
- return c <= 0x7F ? isspace(c) : direction() == DirWS;
-}
-
-inline bool QChar::isDigit() const
-{
- // FIXME: If fast enough, we should just call u_isdigit directly.
- return c <= 0x7F ? isdigit(c) : u_isdigit(c);
-}
-
-inline bool QChar::isLetter() const
-{
- // FIXME: If fast enough, we should just call u_isalpha directly.
- return c <= 0x7F ? isalpha(c) : u_isalpha(c);
-}
-
-inline bool QChar::isNumber() const
-{
- // FIXME: If fast enough, we should just call u_isdigit directly.
- return c <= 0x7F ? isdigit(c) : u_isdigit(c);
-}
-
-inline bool QChar::isLetterOrNumber() const
-{
- // FIXME: If fast enough, we should just call u_isalnum directly.
- return c <= 0x7F ? isalnum(c) : u_isalnum(c);
-}
-
-inline bool QChar::isPunct() const
-{
- return u_ispunct(c);
-}
-
-inline int QChar::digitValue() const
-{
- // FIXME: If fast enough, we should just call u_charDigitValue directly.
- return c <= '9' ? c - '0' : u_charDigitValue(c);
+ return c <= 0x7F ? isspace(c) : (u_charDirection(c) == U_WHITE_SPACE_NEUTRAL);
}
inline QChar QChar::lower() const
return c <= 0x7F ? toupper(c) : u_toupper(c);
}
-inline QChar::Direction QChar::direction() const
-{
- return static_cast<Direction>(u_charDirection(c));
-}
-
inline char QChar::latin1() const
{
return c > 0xff ? 0 : c;
m_fontList->invalidate();
}
-int Font::width(const QChar* chs, int slen, int pos, int len, int tabWidth, int xpos) const
+int Font::width(const UChar* chs, int slen, int pos, int len, int tabWidth, int xpos) const
{
// FIXME: Want to define an lroundf for win32.
#if __APPLE__
void update() const;
void drawText(GraphicsContext*, const IntPoint&, int tabWidth, int xpos,
- const QChar*, int len, int from, int to, int toAdd,
+ const UChar*, int len, int from, int to, int toAdd,
TextDirection, bool visuallyOrdered) const;
void drawHighlightForText(GraphicsContext*, const IntPoint&, int h, int tabWidth, int xpos,
- const QChar*, int len, int from, int to, int toAdd,
+ const UChar*, int len, int from, int to, int toAdd,
TextDirection d, bool visuallyOrdered, const Color& backgroundColor) const;
void drawLineForText(GraphicsContext*, const IntPoint&, int yOffset, int width) const;
void drawLineForMisspelling(GraphicsContext*, const IntPoint&, int width) const;
int misspellingLineThickness(GraphicsContext*) const;
- float floatWidth(const QChar*, int slen, int pos, int len, int tabWidth, int xpos, bool runRounding = true) const;
+ float floatWidth(const UChar*, int slen, int pos, int len, int tabWidth, int xpos, bool runRounding = true) const;
- int checkSelectionPoint(const QChar*, int slen, int pos, int len, int toAdd, int tabWidth, int xpos,
+ int checkSelectionPoint(const UChar*, int slen, int pos, int len, int toAdd, int tabWidth, int xpos,
int x, TextDirection, bool visuallyOrdered, bool includePartialGlyphs) const;
IntRect selectionRectForText(const IntPoint&, int h, int tabWidth, int xpos,
- const QChar*, int slen, int pos, int len, int width,
+ const UChar*, int slen, int pos, int len, int width,
bool rtl, bool visuallyOrdered = false, int from = -1, int to = -1) const;
- int width(const QChar*, int slen, int pos, int len, int tabWidth, int xpos) const;
- int width(const QChar* chs, int slen, int tabWidth = 0, int xpos = 0) const { return width(chs, slen, 0, slen, tabWidth, xpos); }
- int width(const DeprecatedString& s) const { return width(s.unicode(), s.length(), 0, 0); }
+ int width(const UChar*, int slen, int pos, int len, int tabWidth, int xpos) const;
+ int width(const UChar* chs, int slen, int tabWidth = 0, int xpos = 0) const { return width(chs, slen, 0, slen, tabWidth, xpos); }
bool isSmallCaps() const { return m_fontDescription.smallCaps(); }
#include "config.h"
#include "GraphicsContext.h"
+#include "DeprecatedString.h"
#include "Font.h"
using namespace std;
}
// FIXME: We should consider removing this function and having callers just call the lower-level drawText directly.
-// FIXME: The int parameter should change to a HorizontalAlignment parameter.
-// FIXME: HorizontalAlignment should be moved into a separate header so it's not in Widget.h.
// FIXME: We should consider changing this function to take a character pointer and length instead of a DeprecatedString.
-void GraphicsContext::drawText(const IntPoint& point, int horizontalAlignment, const DeprecatedString& str)
+void GraphicsContext::drawText(const IntPoint& point, const DeprecatedString& str)
{
if (paintingDisabled())
return;
- IntPoint p = point;
- if (horizontalAlignment == AlignRight)
- p.setX(p.x() - font().width(str.unicode(), str.length(), 0, 0));
- drawText(p, 0, 0, str.unicode(), str.length(), 0, str.length(), 0);
+ drawText(point, 0, 0, reinterpret_cast<const UChar*>(str.unicode()), str.length(), 0, str.length(), 0);
}
-void GraphicsContext::drawText(const IntPoint& point, int tabWidth, int xpos, const QChar *str, int slen, int pos, int len, int toAdd,
+void GraphicsContext::drawText(const IntPoint& point, int tabWidth, int xpos, const UChar* str, int slen, int pos, int len, int toAdd,
TextDirection d, bool visuallyOrdered, int from, int to)
{
if (paintingDisabled())
font().drawText(this, point, tabWidth, xpos, str + pos, length, from, to, toAdd, d, visuallyOrdered);
}
-void GraphicsContext::drawHighlightForText(const IntPoint& point, int h, int tabWidth, int xpos, const QChar *str, int slen, int pos, int len, int toAdd,
+void GraphicsContext::drawHighlightForText(const IntPoint& point, int h, int tabWidth, int xpos, const UChar* str, int slen, int pos, int len, int toAdd,
TextDirection d, bool visuallyOrdered, int from, int to, const Color& backgroundColor)
{
if (paintingDisabled())
#include "Pen.h"
#include "TextDirection.h"
#include <wtf/Noncopyable.h>
+#include <unicode/umachine.h>
#if __APPLE__
typedef struct CGContext PlatformGraphicsContext;
#endif
class DeprecatedString;
-class QChar;
namespace WebCore {
void setFocusRingClip(const IntRect&);
void clearFocusRingClip();
- void drawText(const IntPoint&, int alignmentFlags, const DeprecatedString&);
+ void drawText(const IntPoint&, const DeprecatedString&);
+ void drawText(const IntPoint&, int tabWidth, int xpos,
+ const UChar*, int slen, int pos, int len, int toAdd,
+ TextDirection = LTR, bool visuallyOrdered = false, int from = -1, int to = -1);
void drawHighlightForText(const IntPoint&, int h, int tabWidth, int xpos,
- const QChar*, int slen, int pos, int len, int toAdd,
+ const UChar*, int slen, int pos, int len, int toAdd,
TextDirection, bool visuallyOrdered,
int from, int to, const Color& backgroundColor);
- void drawText(const IntPoint&, int tabWidth, int xpos,
- const QChar*, int slen, int pos, int len, int toAdd,
- TextDirection = LTR, bool visuallyOrdered = false, int from = -1, int to = -1);
void drawLineForText(const IntPoint&, int yOffset, int width);
void drawLineForMisspelling(const IntPoint&, int width);
int misspellingLineThickness();
* we plan to change this to have immutable copy on write semantics.
*/
-// FIXME: Move to unsigned short instead of QChar.
-
class String {
public:
String() { } // gives null string, distinguishable from an empty string
- String(QChar c) : m_impl(new StringImpl(&c, 1)) { }
- String(const QChar*, unsigned length);
- String(const DeprecatedString&);
+ String(const UChar*, unsigned length);
String(const KJS::Identifier&);
String(const KJS::UString&);
String(const char*);
operator KJS::Identifier() const;
operator KJS::UString() const;
- String& operator +=(const String&);
-
- void insert(const String&, unsigned pos);
+ unsigned length() const;
+ const UChar* characters() const;
- const QChar& operator[](unsigned i) const; // if i >= length(), returns 0
+ UChar operator[](unsigned i) const; // if i >= length(), returns 0
- bool contains(QChar c) const { return find(c) != -1; }
+ bool contains(UChar c) const { return find(c) != -1; }
bool contains(const char* str, bool caseSensitive = true) const { return find(str, 0, caseSensitive) != -1; }
bool contains(const String& str, bool caseSensitive = true) const { return find(str, 0, caseSensitive) != -1; }
- int find(QChar c, int start = 0) const
+ int find(UChar c, int start = 0) const
{ return m_impl ? m_impl->find(c, start) : -1; }
int find(const char* str, int start = 0, bool caseSensitive = true) const
{ return m_impl ? m_impl->find(str, start, caseSensitive) : -1; }
bool endsWith(const String& s, bool caseSensitive = true) const
{ return m_impl ? m_impl->endsWith(s.impl(), caseSensitive) : s.isEmpty(); }
- String& replace(QChar a, QChar b) { if (m_impl) m_impl = m_impl->replace(a, b); return *this; }
- String& replace(QChar a, const String& b) { if (m_impl) m_impl = m_impl->replace(a, b.impl()); return *this; }
+ void append(const String&);
+ void insert(const String&, unsigned pos);
+
+ String& replace(UChar a, UChar b) { if (m_impl) m_impl = m_impl->replace(a, b); return *this; }
+ String& replace(UChar a, const String& b) { if (m_impl) m_impl = m_impl->replace(a, b.impl()); return *this; }
String& replace(unsigned index, unsigned len, const String& b) { if (m_impl) m_impl = m_impl->replace(index, len, b.impl()); return *this; }
- unsigned length() const;
void truncate(unsigned len);
void remove(unsigned pos, int len = 1);
String lower() const;
String upper() const;
- const QChar* unicode() const;
- DeprecatedString deprecatedString() const;
-
+ // Return the string with case folded for case insensitive comparison.
+ String foldCase() const;
+
static String number(int);
static String number(unsigned);
static String number(long);
static String sprintf(const char *, ...)
#if __GNUC__
- __attribute__ ((format (printf, 1, 2)))
+ __attribute__ ((format (printf, 1, 2)))
#endif
- ;
+ ;
int toInt(bool* ok = 0) const;
Length* toLengthArray(int& len) const;
const char *ascii() const;
#endif
+ String(const DeprecatedString&);
+ DeprecatedString deprecatedString() const;
+
private:
RefPtr<StringImpl> m_impl;
};
String operator+(const String&, const String&);
String operator+(const String&, const char*);
String operator+(const char*, const String&);
-String operator+(const String&, QChar);
-String operator+(QChar, const String&);
-String operator+(const String&, char);
-String operator+(char, const String&);
+
+inline String& operator+=(String& a, const String& b) { a.append(b); return a; }
inline bool operator==(const String& a, const String& b) { return equal(a.impl(), b.impl()); }
inline bool operator==(const String& a, const char* b) { return equal(a.impl(), b); }
inline bool equalIgnoringCase(const char* a, const String& b) { return equalIgnoringCase(a, b.impl()); }
bool operator==(const String& a, const DeprecatedString& b);
-inline bool operator==( const DeprecatedString& b, const String& a) { return a == b; }
+inline bool operator==(const DeprecatedString& b, const String& a) { return a == b; }
inline bool operator!=(const String& a, const DeprecatedString& b) { return !(a == b); }
inline bool operator!=(const DeprecatedString& b, const String& a ) { return !(a == b); }
unsigned SegmentedString::length() const
{
unsigned length = m_currentString.m_length;
- if (m_pushedChar1.unicode()) {
+ if (m_pushedChar1) {
++length;
- if (m_pushedChar2.unicode())
+ if (m_pushedChar2)
++length;
}
if (m_composite) {
for (; i != e; ++i)
append(*i);
}
- m_currentChar = m_pushedChar1.unicode() ? &m_pushedChar1 : m_currentString.m_current;
+ m_currentChar = m_pushedChar1 ? &m_pushedChar1 : m_currentString.m_current;
}
void SegmentedString::prepend(const SegmentedString &s)
prepend(*i);
}
prepend(s.m_currentString);
- m_currentChar = m_pushedChar1.unicode() ? &m_pushedChar1 : m_currentString.m_current;
+ m_currentChar = m_pushedChar1 ? &m_pushedChar1 : m_currentString.m_current;
}
void SegmentedString::advanceSubstring()
DeprecatedString SegmentedString::toString() const
{
DeprecatedString result;
- if (m_pushedChar1.unicode()) {
+ if (m_pushedChar1) {
result.append(m_pushedChar1);
- if (m_pushedChar2.unicode())
+ if (m_pushedChar2)
result.append(m_pushedChar2);
}
m_currentString.appendTo(result);
/*
This file is part of the KDE libraries
- Copyright (C) 2004-6 Apple Computer
+ Copyright (C) 2004, 2005, 2006 Apple Computer
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
-//----------------------------------------------------------------------------
-//
-// KDE HTML Widget -- String class
-#ifndef KHTMLSTRING_H
-#define KHTMLSTRING_H
+#ifndef SegmentedString_h
+#define SegmentedString_h
+#include "DeprecatedString.h"
#include "DeprecatedValueList.h"
#include "PlatformString.h"
#include <assert.h>
SegmentedSubstring() : m_length(0), m_current(0) {}
SegmentedSubstring(const DeprecatedString &str) : m_string(str), m_length(str.length()) {
- m_current = m_length == 0 ? 0 : m_string.stableUnicode();
+ m_current = m_length == 0 ? 0 : reinterpret_cast<const UChar*>(m_string.stableUnicode());
}
- SegmentedSubstring(const QChar *str, int length) : m_length(length), m_current(length == 0 ? 0 : str) {}
+ SegmentedSubstring(const UChar* str, int length) : m_length(length), m_current(length == 0 ? 0 : str) {}
void clear() { m_length = 0; m_current = 0; }
- void appendTo(DeprecatedString &str) const {
- if (m_string.unicode() == m_current) {
+ void appendTo(DeprecatedString& str) const {
+ if (reinterpret_cast<const UChar*>(m_string.unicode()) == m_current) {
if (str.isEmpty())
str = m_string;
else
str.append(m_string);
} else {
- str.insert(str.length(), m_current, m_length);
+ str.insert(str.length(), reinterpret_cast<const QChar*>(m_current), m_length);
}
}
DeprecatedString m_string;
int m_length;
- const QChar *m_current;
+ const UChar* m_current;
};
class SegmentedString {
public:
- SegmentedString() : m_currentChar(0), m_lines(0), m_composite(false) {}
- SegmentedString(const QChar *str, int length) : m_currentString(str, length), m_currentChar(m_currentString.m_current), m_lines(0), m_composite(false) {}
- SegmentedString(const DeprecatedString &str) : m_currentString(str), m_currentChar(m_currentString.m_current), m_lines(0), m_composite(false) {}
+ SegmentedString()
+ : m_pushedChar1(0), m_pushedChar2(0), m_currentChar(0)
+ , m_lines(0), m_composite(false) {}
+ SegmentedString(const UChar* str, int length) : m_pushedChar1(0), m_pushedChar2(0)
+ , m_currentString(str, length), m_currentChar(m_currentString.m_current)
+ , m_lines(0), m_composite(false) {}
+ SegmentedString(const DeprecatedString &str)
+ : m_pushedChar1(0), m_pushedChar2(0), m_currentString(str)
+ , m_currentChar(m_currentString.m_current)
+ , m_lines(0), m_composite(false) {}
SegmentedString(const SegmentedString&);
const SegmentedString& operator=(const SegmentedString&);
void append(const SegmentedString &);
void prepend(const SegmentedString &);
- void push(QChar c) {
- if (!m_pushedChar1.unicode()) {
+ void push(UChar c) {
+ if (!m_pushedChar1) {
m_pushedChar1 = c;
- m_currentChar = m_pushedChar1.unicode() ? &m_pushedChar1 : m_currentString.m_current;
+ m_currentChar = m_pushedChar1 ? &m_pushedChar1 : m_currentString.m_current;
} else {
- assert(!m_pushedChar2.unicode());
+ assert(!m_pushedChar2);
m_pushedChar2 = c;
}
}
unsigned length() const;
void advance() {
- if (m_pushedChar1.unicode()) {
+ if (m_pushedChar1) {
m_pushedChar1 = m_pushedChar2;
m_pushedChar2 = 0;
} else if (m_currentString.m_current) {
if (--m_currentString.m_length == 0)
advanceSubstring();
}
- m_currentChar = m_pushedChar1.unicode() ? &m_pushedChar1 : m_currentString.m_current;
+ m_currentChar = m_pushedChar1 ? &m_pushedChar1 : m_currentString.m_current;
}
- bool escaped() const { return m_pushedChar1.unicode(); }
+ bool escaped() const { return m_pushedChar1; }
int lineCount() const { return m_lines; }
void resetLineCount() { m_lines = 0; }
DeprecatedString toString() const;
void operator++() { advance(); }
- const QChar &operator*() const { return *current(); }
- const QChar *operator->() const { return current(); }
+ const UChar& operator*() const { return *current(); }
+ const UChar* operator->() const { return current(); }
private:
void append(const SegmentedSubstring &);
void prepend(const SegmentedSubstring &);
void advanceSubstring();
- const QChar *current() const { return m_currentChar; }
+ const UChar* current() const { return m_currentChar; }
- QChar m_pushedChar1;
- QChar m_pushedChar2;
+ UChar m_pushedChar1;
+ UChar m_pushedChar2;
SegmentedSubstring m_currentString;
- const QChar *m_currentChar;
+ const UChar* m_currentChar;
DeprecatedValueList<SegmentedSubstring> m_substrings;
int m_lines;
bool m_composite;
static const UChar replacementCharacter = 0xFFFD;
static const UChar BOM = 0xFEFF;
-static const int ConversionBufferSize = 16384;
+static const size_t ConversionBufferSize = 16384;
static UConverter* cachedConverterICU;
static TextEncodingID cachedConverterEncoding = InvalidEncoding;
}
}
-DeprecatedString StreamingTextDecoder::convertUTF16(const unsigned char *s, int length)
+DeprecatedString StreamingTextDecoder::convertUTF16(const unsigned char* s, int length)
{
ASSERT(m_numBufferedBytes == 0 || m_numBufferedBytes == 1);
- const unsigned char *p = s;
- unsigned len = length;
+ const unsigned char* p = s;
+ size_t len = length;
DeprecatedString result("");
c = (m_bufferedBytes[0] << 8) | p[0];
if (c)
- result.append(reinterpret_cast<QChar *>(&c), 1);
+ result.append(reinterpret_cast<QChar*>(&c), 1);
m_numBufferedBytes = 0;
p += 1;
while (len > 1) {
UChar buffer[ConversionBufferSize];
- int runLength = min(len / 2, (unsigned)(sizeof(buffer) / sizeof(buffer[0])));
+ int runLength = min(len / 2, ConversionBufferSize);
int bufferLength = 0;
if (m_littleEndian) {
for (int i = 0; i < runLength; ++i) {
UChar c = p[0] | (p[1] << 8);
p += 2;
- if (c && c != BOM)
+ if (c != BOM)
buffer[bufferLength++] = c;
}
} else {
for (int i = 0; i < runLength; ++i) {
UChar c = (p[0] << 8) | p[1];
p += 2;
- if (c && c != BOM)
+ if (c != BOM)
buffer[bufferLength++] = c;
}
}
- result.append(reinterpret_cast<QChar *>(buffer), bufferLength);
+ result.append(reinterpret_cast<QChar*>(buffer), bufferLength);
len -= runLength * 2;
}
return result;
}
+bool StreamingTextDecoder::convertIfASCII(const unsigned char* s, int length, DeprecatedString& str)
+{
+ ASSERT(m_numBufferedBytes == 0 || m_numBufferedBytes == 1);
+
+ DeprecatedString result("");
+ result.reserve(length);
+
+ const unsigned char* p = s;
+ size_t len = length;
+ unsigned char ored = 0;
+ while (len) {
+ UChar buffer[ConversionBufferSize];
+ int runLength = min(len, ConversionBufferSize);
+ int bufferLength = 0;
+ for (int i = 0; i < runLength; ++i) {
+ unsigned char c = *p++;
+ ored |= c;
+ buffer[bufferLength++] = c;
+ }
+ if (ored & 0x80)
+ return false;
+ result.append(reinterpret_cast<QChar*>(buffer), bufferLength);
+ len -= runLength;
+ }
+
+ str = result;
+ return true;
+}
+
static inline TextEncoding effectiveEncoding(const TextEncoding& encoding)
{
TextEncodingID id = encoding.encodingID();
return TextEncoding(id, encoding.flags());
}
-UErrorCode StreamingTextDecoder::createICUConverter()
+void StreamingTextDecoder::createICUConverter()
{
TextEncoding encoding = effectiveEncoding(m_encoding);
const char* encodingName = encoding.name();
UErrorCode err = U_ZERO_ERROR;
ASSERT(!m_converterICU);
m_converterICU = ucnv_open(encodingName, &err);
+#if !LOG_DISABLED
if (err == U_AMBIGUOUS_ALIAS_WARNING)
LOG_ERROR("ICU ambiguous alias warning for encoding: %s", encodingName);
-
- if (!m_converterICU) {
+ if (!m_converterICU)
LOG_ERROR("the ICU Converter won't convert from text encoding 0x%X, error %d", encoding.encodingID(), err);
- return err;
- }
+#endif
}
-
- return U_ZERO_ERROR;
}
// We strip replacement characters because the ICU converter for UTF-8 converts
return c == replacementCharacter || c == BOM;
}
-void StreamingTextDecoder::appendOmittingUnwanted(DeprecatedString &s, const UChar *characters, int byteCount)
+void StreamingTextDecoder::appendOmittingUnwanted(DeprecatedString& s, const UChar* characters, int byteCount)
{
ASSERT(byteCount % sizeof(UChar) == 0);
int start = 0;
for (int i = 0; i != characterCount; ++i) {
if (unwanted(characters[i])) {
if (start != i)
- s.append(reinterpret_cast<const QChar *>(&characters[start]), i - start);
+ s.append(reinterpret_cast<const QChar*>(&characters[start]), i - start);
start = i + 1;
}
}
if (start != characterCount)
- s.append(reinterpret_cast<const QChar *>(&characters[start]), characterCount - start);
+ s.append(reinterpret_cast<const QChar*>(&characters[start]), characterCount - start);
}
-DeprecatedString StreamingTextDecoder::convertUsingICU(const unsigned char *chs, int len, bool flush)
+DeprecatedString StreamingTextDecoder::convertUsingICU(const unsigned char* chs, int len, bool flush)
{
// Get a converter for the passed-in encoding.
- if (!m_converterICU && U_FAILURE(createICUConverter()))
- return DeprecatedString();
-
- ASSERT(m_converterICU);
+ if (!m_converterICU) {
+ createICUConverter();
+ if (!m_converterICU)
+ return DeprecatedString();
+ }
DeprecatedString result("");
result.reserve(len);
UChar buffer[ConversionBufferSize];
- const char *source = reinterpret_cast<const char *>(chs);
- const char *sourceLimit = source + len;
- int32_t *offsets = NULL;
+ const char* source = reinterpret_cast<const char*>(chs);
+ const char* sourceLimit = source + len;
+ int32_t* offsets = NULL;
UErrorCode err;
-
+
do {
- UChar *target = buffer;
- const UChar *targetLimit = target + ConversionBufferSize;
+ UChar* target = buffer;
+ const UChar* targetLimit = target + ConversionBufferSize;
err = U_ZERO_ERROR;
ucnv_toUnicode(m_converterICU, &target, targetLimit, &source, sourceLimit, offsets, flush, &err);
int count = target - buffer;
- appendOmittingUnwanted(result, reinterpret_cast<const UChar *>(buffer), count * sizeof(UChar));
+ appendOmittingUnwanted(result, reinterpret_cast<const UChar*>(buffer), count * sizeof(UChar));
} while (err == U_BUFFER_OVERFLOW_ERROR);
if (U_FAILURE(err)) {
LOG_ERROR("ICU conversion error");
return DeprecatedString();
}
-
+
return result;
}
-DeprecatedString StreamingTextDecoder::convert(const unsigned char *chs, int len, bool flush)
+DeprecatedString StreamingTextDecoder::convert(const unsigned char* chs, int len, bool flush)
{
- //#define PARTIAL_CHARACTER_HANDLING_TEST_CHUNK_SIZE 1000
-
switch (m_encoding.encodingID()) {
- case UTF16Encoding:
- return convertUTF16(chs, len);
+ case UTF16Encoding:
+ return convertUTF16(chs, len);
+
+ case ASCIIEncoding:
+ case Latin1Encoding:
+ case WinLatin1Encoding: {
+ DeprecatedString result;
+ if (convertIfASCII(chs, len, result))
+ return result;
+ break;
+ }
- default:
-#if PARTIAL_CHARACTER_HANDLING_TEST_CHUNK_SIZE
- DeprecatedString result;
- int chunkSize;
- for (int i = 0; i != len; i += chunkSize) {
- chunkSize = len - i;
- if (chunkSize > PARTIAL_CHARACTER_HANDLING_TEST_CHUNK_SIZE) {
- chunkSize = PARTIAL_CHARACTER_HANDLING_TEST_CHUNK_SIZE;
+ case UTF8Encoding:
+ // If a previous run used ICU, we might have a partly converted character.
+ // If so, don't use the optimized ASCII code path.
+ if (!m_converterICU) {
+ DeprecatedString result;
+ if (convertIfASCII(chs, len, result))
+ return result;
}
- result += convertUsingICU(chs + i, chunkSize, flush && (i + chunkSize == len));
+ break;
+
+ default:
+ break;
+ }
+
+ //#define PARTIAL_CHARACTER_HANDLING_TEST_CHUNK_SIZE 1000
+#if PARTIAL_CHARACTER_HANDLING_TEST_CHUNK_SIZE
+ DeprecatedString result;
+ int chunkSize;
+ for (int i = 0; i != len; i += chunkSize) {
+ chunkSize = len - i;
+ if (chunkSize > PARTIAL_CHARACTER_HANDLING_TEST_CHUNK_SIZE) {
+ chunkSize = PARTIAL_CHARACTER_HANDLING_TEST_CHUNK_SIZE;
}
- return result;
+ result += convertUsingICU(chs + i, chunkSize, flush && (i + chunkSize == len));
+ }
+ return result;
#else
- return convertUsingICU(chs, len, flush);
+ return convertUsingICU(chs, len, flush);
#endif
- }
- ASSERT_NOT_REACHED();
- return DeprecatedString();
}
-DeprecatedString StreamingTextDecoder::toUnicode(const char *chs, int len, bool flush)
+DeprecatedString StreamingTextDecoder::toUnicode(const char* chs, int len, bool flush)
{
ASSERT_ARG(len, len >= 0);
int numBufferedBytes = m_numBufferedBytes;
int buf1Len = numBufferedBytes;
int buf2Len = len;
- const unsigned char *buf1 = m_bufferedBytes;
- const unsigned char *buf2 = reinterpret_cast<const unsigned char *>(chs);
+ const unsigned char* buf1 = m_bufferedBytes;
+ const unsigned char* buf2 = reinterpret_cast<const unsigned char*>(chs);
unsigned char c1 = buf1Len ? (--buf1Len, *buf1++) : buf2Len ? (--buf2Len, *buf2++) : 0;
unsigned char c2 = buf1Len ? (--buf1Len, *buf1++) : buf2Len ? (--buf2Len, *buf2++) : 0;
unsigned char c3 = buf1Len ? (--buf1Len, *buf1++) : buf2Len ? (--buf2Len, *buf2++) : 0;
public:
StreamingTextDecoder(const TextEncoding&);
~StreamingTextDecoder();
-
+
DeprecatedString toUnicode(const char* chs, int len, bool flush = false);
-
+
private:
- DeprecatedString convert(const char*chs, int len, bool flush)
+ DeprecatedString convert(const char* chs, int len, bool flush)
{ return convert(reinterpret_cast<const unsigned char*>(chs), len, flush); }
DeprecatedString convert(const unsigned char* chs, int len, bool flush);
- DeprecatedString convertUTF16(const unsigned char* chs, int len);
-
- // ICU decoding.
- DeprecatedString convertUsingICU(const unsigned char *chs, int len, bool flush);
- UErrorCode createICUConverter();
- static void appendOmittingUnwanted(DeprecatedString& s, const UChar* characters, int byteCount);
+ bool convertIfASCII(const unsigned char*, int len, DeprecatedString&);
+ DeprecatedString convertUTF16(const unsigned char*, int len);
+ DeprecatedString convertUsingICU(const unsigned char*, int len, bool flush);
+
+ void createICUConverter();
+
+ static void appendOmittingUnwanted(DeprecatedString&, const UChar* characters, int byteCount);
TextEncoding m_encoding;
bool m_littleEndian;
#include "config.h"
#include "PlatformString.h"
+#include "DeprecatedString.h"
#include <kjs/identifier.h>
#include <wtf/Vector.h>
#include <stdarg.h>
-using namespace KJS;
+using KJS::Identifier;
+using KJS::UString;
namespace WebCore {
-String::String(const QChar* str, unsigned len)
+String::String(const UChar* str, unsigned len)
{
if (!str)
return;
if (str.isEmpty())
m_impl = StringImpl::empty();
else
- m_impl = new StringImpl(str.unicode(), str.length());
+ m_impl = new StringImpl(reinterpret_cast<const UChar*>(str.unicode()), str.length());
}
String::String(const char* str)
m_impl = new StringImpl(str, length);
}
-String& String::operator+=(const String &str)
+void String::append(const String &str)
{
if (str.m_impl) {
if (!m_impl) {
// ### FIXME!!!
m_impl = str.m_impl;
- return *this;
+ return;
}
m_impl = m_impl->copy();
m_impl->append(str.m_impl.get());
}
- return *this;
}
String operator+(const String& a, const String& b)
return String(cs) + s;
}
-String operator+(const String& s, QChar c)
-{
- return s + String(c);
-}
-
-String operator+(QChar c, const String& s)
-{
- return String(c) + s;
-}
-
-String operator+(const String& s, char c)
-{
- return s + String(c);
-}
-
-String operator+(char c, const String& s)
-{
- return String(c) + s;
-}
-
void String::insert(const String& str, unsigned pos)
{
if (!m_impl)
m_impl->insert(str.m_impl.get(), pos);
}
-const QChar& String::operator[](unsigned i) const
+UChar String::operator[](unsigned i) const
{
- static const QChar nullChar = 0;
- if (!m_impl || i >= m_impl->length() )
- return nullChar;
- return *(m_impl->unicode()+i);
+ if (!m_impl || i >= m_impl->length())
+ return 0;
+ return m_impl->characters()[i];
}
unsigned String::length() const
return m_impl->upper();
}
+String String::foldCase() const
+{
+ if (!m_impl)
+ return String();
+ return m_impl->foldCase();
+}
+
bool String::percentage(int& result) const
{
if (!m_impl || !m_impl->length())
return false;
- if (*(m_impl->unicode()+m_impl->length()-1) != '%')
+ if ((*m_impl)[m_impl->length() - 1] != '%')
return false;
- result = QConstString(m_impl->unicode(), m_impl->length()-1).string().toInt();
+ result = QConstString(reinterpret_cast<const QChar*>(m_impl->characters()), m_impl->length() - 1).string().toInt();
return true;
}
-const QChar* String::unicode() const
+const UChar* String::characters() const
{
if (!m_impl)
return 0;
- return m_impl->unicode();
+ return m_impl->characters();
}
DeprecatedString String::deprecatedString() const
{
if (!m_impl)
return DeprecatedString::null;
- if (!m_impl->unicode())
+ if (!m_impl->characters())
return DeprecatedString("", 0);
- return DeprecatedString(m_impl->unicode(), m_impl->length());
+ return DeprecatedString(reinterpret_cast<const QChar*>(m_impl->characters()), m_impl->length());
}
String String::sprintf(const char *format, ...)
Vector<char, 256> buffer;
#if PLATFORM(WIN_OS)
- // Windows vnsprintf does not return the expected size on overflow
+ // Windows vsnprintf does not return the expected size on overflow
// So we just have to keep looping until our vsprintf call works!
int result = 0;
do {
if (result < 0)
buffer.resize(buffer.capacity() * 2);
result = vsnprintf(buffer.data(), buffer.capacity(), format, args);
- // Windows vnsprintf returns -1 both for all errors. There is no
+ // Windows vsnprintf returns -1 for both errors. Since there is no
// way to distinguish between "not enough room" and "invalid format"
// we just keep trying until we hit an arbitrary size and then stop.
} while (result < 0 && (buffer.capacity() * 2) < 2048);
bool String::isEmpty() const
{
- return (!m_impl || m_impl->length() == 0);
+ return !m_impl || !m_impl->length();
}
Length* String::toCoordsArray(int& len) const
unsigned l = a.length();
if (l != b.length())
return false;
- if (!memcmp(a.unicode(), b.unicode(), l * sizeof(QChar)))
+ if (!memcmp(a.characters(), b.unicode(), l * sizeof(UChar)))
return true;
return false;
}
if (str.isEmpty())
m_impl = StringImpl::empty();
else
- m_impl = new StringImpl(reinterpret_cast<const QChar*>(str.data()), str.size());
+ m_impl = new StringImpl(reinterpret_cast<const UChar*>(str.data()), str.size());
}
String::String(const UString& str)
if (str.isEmpty())
m_impl = StringImpl::empty();
else
- m_impl = new StringImpl(reinterpret_cast<const QChar*>(str.data()), str.size());
+ m_impl = new StringImpl(reinterpret_cast<const UChar*>(str.data()), str.size());
}
String::operator Identifier() const
{
if (!m_impl)
return Identifier();
- return Identifier(reinterpret_cast<const KJS::UChar*>(m_impl->unicode()), m_impl->length());
+ return Identifier(reinterpret_cast<const KJS::UChar*>(m_impl->characters()), m_impl->length());
}
String::operator UString() const
{
if (!m_impl)
return UString();
- return UString(reinterpret_cast<const KJS::UChar*>(m_impl->unicode()), m_impl->length());
+ return UString(reinterpret_cast<const KJS::UChar*>(m_impl->characters()), m_impl->length());
}
}
#include "AtomicStringImpl.h"
#include "PlatformString.h"
#include <wtf/HashTraits.h>
+#include <unicode/uchar.h>
+#include <unicode/ustring.h>
namespace WTF {
if (aLength != bLength)
return false;
- const uint32_t* aChars = reinterpret_cast<const uint32_t*>(a->unicode());
- const uint32_t* bChars = reinterpret_cast<const uint32_t*>(b->unicode());
+ const uint32_t* aChars = reinterpret_cast<const uint32_t*>(a->characters());
+ const uint32_t* bChars = reinterpret_cast<const uint32_t*>(b->characters());
unsigned halfLength = aLength >> 1;
for (unsigned i = 0; i != halfLength; ++i)
static unsigned hash(const WebCore::StringImpl* str)
{
unsigned l = str->length();
- const QChar* s = str->unicode();
+ const UChar* s = str->characters();
uint32_t hash = PHI;
uint32_t tmp;
// Main loop
for (; l > 0; l--) {
- hash += s[0].lower().unicode();
- tmp = (s[1].lower().unicode() << 11) ^ hash;
+ hash += u_foldCase(s[0], U_FOLD_CASE_DEFAULT);
+ tmp = (u_foldCase(s[1], U_FOLD_CASE_DEFAULT) << 11) ^ hash;
hash = (hash << 16) ^ tmp;
s += 2;
hash += hash >> 11;
// Handle end case
if (rem) {
- hash += s[0].lower().unicode();
+ hash += u_foldCase(s[0], U_FOLD_CASE_DEFAULT);
hash ^= hash << 11;
hash += hash >> 17;
}
// Main loop
for (; l > 0; l--) {
- hash += QChar(s[0]).lower().unicode();
- tmp = (QChar(s[1]).lower().unicode() << 11) ^ hash;
+ hash += u_foldCase(s[0], U_FOLD_CASE_DEFAULT);
+ tmp = (u_foldCase(s[1], U_FOLD_CASE_DEFAULT) << 11) ^ hash;
hash = (hash << 16) ^ tmp;
s += 2;
hash += hash >> 11;
// Handle end case
if (rem) {
- hash += QChar(s[0]).lower().unicode();
+ hash += u_foldCase(s[0], U_FOLD_CASE_DEFAULT);
hash ^= hash << 11;
hash += hash >> 17;
}
static bool equal(const WebCore::StringImpl* a, const WebCore::StringImpl* b)
{
- if (a == b) return true;
- if (!a || !b) return false;
+ if (a == b)
+ return true;
+ if (!a || !b)
+ return false;
unsigned length = a->length();
if (length != b->length())
return false;
- const QChar* as = a->unicode();
- const QChar* bs = b->unicode();
- for (unsigned i = 0; i != length; ++i)
- if (as[i].lower() != bs[i].lower())
- return false;
- return true;
+ return u_memcasecmp(a->characters(), b->characters(), length, U_FOLD_CASE_DEFAULT) == 0;
}
};
- template<> struct StrHash<WebCore::AtomicStringImpl*> : public StrHash<WebCore::StringImpl*> {
- };
+ template<> struct StrHash<WebCore::AtomicStringImpl*> : public StrHash<WebCore::StringImpl*> { };
template<> struct StrHash<RefPtr<WebCore::StringImpl> > {
static unsigned hash(const RefPtr<WebCore::StringImpl>& key) { return key->hash(); }
#include "StringImpl.h"
#include "AtomicString.h"
+#include "DeprecatedString.h"
#include "Length.h"
#include "StringHash.h"
#include <kjs/identifier.h>
#include <wtf/Assertions.h>
#include <unicode/ubrk.h>
+#include <unicode/ustring.h>
#include <assert.h>
-using namespace KJS;
using namespace WTF;
+using KJS::Identifier;
+using KJS::UString;
+
namespace WebCore {
-static inline QChar* newQCharVector(unsigned n)
+const UChar nonBreakingSpace = 0xA0;
+
+static inline UChar* newUCharVector(unsigned n)
{
- return static_cast<QChar*>(fastMalloc(sizeof(QChar) * n));
+ return static_cast<UChar*>(fastMalloc(sizeof(UChar) * n));
}
-static inline void deleteQCharVector(QChar* p)
+static inline void deleteUCharVector(UChar* p)
{
fastFree(p);
}
StringImpl::StringImpl(const DeprecatedString& str)
{
- initWithQChar(str.unicode(), str.length());
+ init(reinterpret_cast<const UChar*>(str.unicode()), str.length());
}
-StringImpl::StringImpl(const QChar* str, unsigned len)
+StringImpl::StringImpl(const UChar* str, unsigned len)
{
- initWithQChar(str, len);
+ init(str, len);
}
StringImpl::StringImpl(const char* str)
{
- initWithChar(str, strlen(str));
+ init(str, strlen(str));
}
StringImpl::StringImpl(const char* str, unsigned len)
{
- initWithChar(str, len);
+ init(str, len);
}
-void StringImpl::initWithChar(const char* str, unsigned len)
+void StringImpl::init(const char* str, unsigned len)
{
m_hash = 0;
m_inTable = false;
return;
}
- m_data = newQCharVector(m_length);
+ m_data = newUCharVector(m_length);
int i = m_length;
- QChar* ptr = m_data;
+ UChar* ptr = m_data;
while (i--)
*ptr++ = *str++;
}
-void StringImpl::initWithQChar(const QChar* str, unsigned len)
+void StringImpl::init(const UChar* str, unsigned len)
{
m_hash = 0;
m_inTable = false;
return;
}
- m_data = newQCharVector(len);
- memcpy(m_data, str, len * sizeof(QChar));
+ m_data = newUCharVector(len);
+ memcpy(m_data, str, len * sizeof(UChar));
}
StringImpl::~StringImpl()
{
if (m_inTable)
AtomicString::remove(this);
- deleteQCharVector(m_data);
+ deleteUCharVector(m_data);
}
void StringImpl::append(const StringImpl* str)
if(str && str->m_length != 0)
{
int newlen = m_length+str->m_length;
- QChar* c = newQCharVector(newlen);
- memcpy(c, m_data, m_length*sizeof(QChar));
- memcpy(c+m_length, str->m_data, str->m_length*sizeof(QChar));
- deleteQCharVector(m_data);
+ UChar* c = newUCharVector(newlen);
+ memcpy(c, m_data, m_length * sizeof(UChar));
+ memcpy(c + m_length, str->m_data, str->m_length * sizeof(UChar));
+ deleteUCharVector(m_data);
m_data = c;
m_length = newlen;
}
}
if (str && str->m_length != 0) {
int newlen = m_length + str->m_length;
- QChar* c = newQCharVector(newlen);
- memcpy(c, m_data, pos*sizeof(QChar));
- memcpy(c+pos, str->m_data, str->m_length*sizeof(QChar));
- memcpy(c+pos+str->m_length, m_data+pos, (m_length-pos)*sizeof(QChar));
- deleteQCharVector(m_data);
+ UChar* c = newUCharVector(newlen);
+ memcpy(c, m_data, pos * sizeof(UChar));
+ memcpy(c + pos, str->m_data, str->m_length * sizeof(UChar));
+ memcpy(c + pos + str->m_length, m_data + pos, (m_length - pos) * sizeof(UChar));
+ deleteUCharVector(m_data);
m_data = c;
m_length = newlen;
}
if (len >= (int)m_length)
return;
int nl = len < 1 ? 1 : len;
- QChar* c = newQCharVector(nl);
- memcpy(c, m_data, nl*sizeof(QChar));
- deleteQCharVector(m_data);
+ UChar* c = newUCharVector(nl);
+ memcpy(c, m_data, nl * sizeof(UChar));
+ deleteUCharVector(m_data);
m_data = c;
m_length = len;
}
assert(!m_inTable);
if (len <= 0)
return;
- if (pos >= m_length )
+ if (pos >= m_length)
return;
if ((unsigned)len > m_length - pos)
len = m_length - pos;
unsigned newLen = m_length-len;
- QChar* c = newQCharVector(newLen);
- memcpy(c, m_data, pos*sizeof(QChar));
- memcpy(c+pos, m_data+pos+len, (m_length-len-pos)*sizeof(QChar));
- deleteQCharVector(m_data);
+ UChar* c = newUCharVector(newLen);
+ memcpy(c, m_data, pos * sizeof(UChar));
+ memcpy(c + pos, m_data + pos + len, (m_length - len - pos) * sizeof(UChar));
+ deleteUCharVector(m_data);
m_data = c;
m_length = newLen;
}
if( pos >=m_length ) return new StringImpl();
unsigned newLen = m_length-pos;
- QChar* c = newQCharVector(newLen);
- memcpy(c, m_data+pos, newLen*sizeof(QChar));
+ UChar* c = newUCharVector(newLen);
+ memcpy(c, m_data + pos, newLen * sizeof(UChar));
StringImpl* str = new StringImpl(m_data + pos, newLen);
truncate(pos);
{
if (!m_data)
return true;
-
- for (unsigned i = from; i < len; i++) {
- QChar c = m_data[i];
- if (c.unicode() <= 0x7F) {
- if (!isspace(c.unicode()))
- return false;
- }
- else
+ // FIXME: Both the definition of what whitespace is, and the definition of what
+ // the "len" parameter means are different here from what's done in RenderText.
+ // FIXME: No range checking here.
+ for (unsigned i = from; i < len; i++)
+ if (m_data[i] > 0x7F || !isspace(m_data[i]))
return false;
- }
return true;
}
return new StringImpl(m_data + pos, len);
}
-static Length parseLength(const QChar* m_data, unsigned int m_length)
+static Length parseLength(const UChar* m_data, unsigned int m_length)
{
if (m_length == 0)
return Length(1, Relative);
unsigned i = 0;
- while (i < m_length && m_data[i].isSpace())
+ while (i < m_length && QChar(m_data[i]).isSpace())
++i;
if (i < m_length && (m_data[i] == '+' || m_data[i] == '-'))
++i;
- while (i < m_length && m_data[i].isDigit())
+ while (i < m_length && u_isdigit(m_data[i]))
++i;
bool ok;
- int r = QConstString(m_data, i).string().toInt(&ok);
+ int r = QConstString(reinterpret_cast<const QChar*>(m_data), i).string().toInt(&ok);
/* Skip over any remaining digits, we are not that accurate (5.5% => 5%) */
- while (i < m_length && (m_data[i].isDigit() || m_data[i] == '.'))
+ while (i < m_length && (u_isdigit(m_data[i]) || m_data[i] == '.'))
++i;
/* IE Quirk: Skip any whitespace (20 % => 20%) */
- while (i < m_length && m_data[i].isSpace())
+ while (i < m_length && QChar(m_data[i]).isSpace())
++i;
if (ok) {
- if (i == m_length)
- return Length(r, Fixed);
- else {
- const QChar* next = m_data+i;
-
- if (*next == '%')
+ if (i < m_length) {
+ UChar next = m_data[i];
+ if (next == '%')
return Length(r, Percent);
-
- if (*next == '*')
+ if (next == '*')
return Length(r, Relative);
}
return Length(r, Fixed);
} else {
if (i < m_length) {
- const QChar* next = m_data + i;
-
- if (*next == '*')
+ UChar next = m_data[i];
+ if (next == '*')
return Length(1, Relative);
-
- if (*next == '%')
+ if (next == '%')
return Length(1, Relative);
}
}
Length* StringImpl::toCoordsArray(int& len) const
{
- QChar* spacified = newQCharVector(m_length);
- QChar space(' ');
- for (unsigned int i=0; i < m_length; i++) {
- QChar cc = m_data[i];
- if (cc.unicode() > '9' || (cc.unicode() < '0' && cc != '-' && cc != '*' && cc != '.'))
- spacified[i] = space;
+ UChar* spacified = newUCharVector(m_length);
+ for (unsigned i = 0; i < m_length; i++) {
+ UChar cc = m_data[i];
+ if (cc > '9' || (cc < '0' && cc != '-' && cc != '*' && cc != '.'))
+ spacified[i] = ' ';
else
spacified[i] = cc;
}
- DeprecatedString str(spacified, m_length);
- deleteQCharVector(spacified);
+ DeprecatedString str(reinterpret_cast<const QChar*>(spacified), m_length);
+ deleteUCharVector(spacified);
str = str.simplifyWhiteSpace();
int pos2;
while((pos2 = str.find(' ', pos)) != -1) {
- r[i++] = parseLength(str.unicode() + pos, pos2-pos);
+ r[i++] = parseLength(reinterpret_cast<const UChar*>(str.unicode()) + pos, pos2 - pos);
pos = pos2+1;
}
- r[i] = parseLength(str.unicode() + pos, str.length()-pos);
+ r[i] = parseLength(reinterpret_cast<const UChar*>(str.unicode()) + pos, str.length() - pos);
return r;
}
len = 1;
return 0;
}
- DeprecatedString str(m_data, m_length);
+ DeprecatedString str(reinterpret_cast<const QChar*>(m_data), m_length);
str = str.simplifyWhiteSpace();
len = str.contains(',') + 1;
int pos = 0;
int pos2;
- while((pos2 = str.find(',', pos)) != -1) {
- r[i++] = parseLength(str.unicode() + pos, pos2 - pos);
+ while ((pos2 = str.find(',', pos)) != -1) {
+ r[i++] = parseLength(reinterpret_cast<const UChar*>(str.unicode()) + pos, pos2 - pos);
pos = pos2+1;
}
/* IE Quirk: If the last comma is the last char skip it and reduce len by one */
if (str.length()-pos > 0)
- r[i] = parseLength(str.unicode() + pos, str.length() - pos);
+ r[i] = parseLength(reinterpret_cast<const UChar*>(str.unicode()) + pos, str.length() - pos);
else
len--;
bool StringImpl::isLower() const
{
- unsigned int i;
- for (i = 0; i < m_length; i++)
- if (m_data[i].lower() != m_data[i])
- return false;
- return true;
+ // Do a quick check for the case where it's all ASCII.
+ int allLower = true;
+ UChar ored = 0;
+ for (unsigned i = 0; i < m_length; i++) {
+ UChar c = m_data[i];
+ allLower &= islower(c);
+ ored |= c;
+ }
+ if (!(ored & ~0x7F))
+ return allLower;
+
+ // Do a slower check for the other cases.
+ UBool allLower2 = true;
+ for (unsigned i = 0; i < m_length; i++)
+ allLower2 &= u_islower(m_data[i]);
+ return allLower2;
}
StringImpl* StringImpl::lower() const
if (!m_length)
return c;
- c->m_data = newQCharVector(m_length);
- c->m_length = m_length;
+ UChar* data = newUCharVector(m_length);
+ int length = m_length;
- for (unsigned int i = 0; i < m_length; i++)
- c->m_data[i] = m_data[i].lower();
+ c->m_data = data;
+ c->m_length = length;
+ // Do a faster loop for the case where it's all ASCII.
+ UChar ored = 0;
+ for (int i = 0; i < length; i++) {
+ UChar c = m_data[i];
+ ored |= c;
+ data[i] = tolower(c);
+ }
+ if (!(ored & ~0x7F))
+ return c;
+
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t realLength = u_strToLower(data, length, m_data, length, "", &status);
+ if (U_SUCCESS(status) && realLength == length)
+ return c;
+
+ if (realLength > length) {
+ deleteUCharVector(data);
+ data = newUCharVector(realLength);
+ }
+ length = realLength;
+
+ c->m_data = data;
+ c->m_length = length;
+
+ status = U_ZERO_ERROR;
+ u_strToLower(data, length, m_data, m_length, "", &status);
+ if (U_FAILURE(status)) {
+ c->ref();
+ c->deref();
+ return copy();
+ }
return c;
}
StringImpl* c = new StringImpl;
if (!m_length)
return c;
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t length = u_strToUpper(0, 0, m_data, m_length, "", &status);
+ c->m_data = newUCharVector(length);
+ c->m_length = length;
+ status = U_ZERO_ERROR;
+ u_strToUpper(c->m_data, length, m_data, m_length, "", &status);
+ if (U_FAILURE(status)) {
+ c->ref();
+ c->deref();
+ return copy();
+ }
+ return c;
+}
- c->m_data = newQCharVector(m_length);
- c->m_length = m_length;
-
- for (unsigned int i = 0; i < m_length; i++)
- c->m_data[i] = m_data[i].upper();
-
+StringImpl* StringImpl::foldCase() const
+{
+ StringImpl* c = new StringImpl;
+ if (!m_length)
+ return c;
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t length = u_strFoldCase(0, 0, m_data, m_length, U_FOLD_CASE_DEFAULT, &status);
+ c->m_data = newUCharVector(length);
+ c->m_length = length;
+ status = U_ZERO_ERROR;
+ u_strFoldCase(c->m_data, length, m_data, m_length, U_FOLD_CASE_DEFAULT, &status);
+ if (U_FAILURE(status)) {
+ c->ref();
+ c->deref();
+ return copy();
+ }
return c;
}
-static UBreakIterator* getWordBreakIterator(const QChar* string, int length)
+static UBreakIterator* getWordBreakIterator(const UChar* string, int length)
{
// The locale is currently ignored when determining character cluster breaks.
// This may change in the future, according to Deborah Goldsmith.
status = U_ZERO_ERROR;
ubrk_setText(iterator, reinterpret_cast<const ::UChar*>(string), length, &status);
- if (status != U_ZERO_ERROR)
+ if (U_FAILURE(status))
return 0;
return iterator;
}
-StringImpl* StringImpl::capitalize(QChar previous) const
+StringImpl* StringImpl::capitalize(UChar previous) const
{
StringImpl* capitalizedString = new StringImpl;
if (!m_length)
return capitalizedString;
- QChar* stringWithPrevious = newQCharVector(m_length + 1);
+ UChar* stringWithPrevious = newUCharVector(m_length + 1);
stringWithPrevious[0] = previous;
- const char nonBreakingSpace = '\xa0';
for (unsigned i = 1; i < m_length + 1; i++) {
// Replace   with a real space since ICU no longer treats   as a word separator.
if (m_data[i - 1] == nonBreakingSpace)
else
stringWithPrevious[i] = m_data[i - 1];
}
-
+
UBreakIterator* boundary = getWordBreakIterator(stringWithPrevious, m_length + 1);
if (!boundary) {
- deleteQCharVector(stringWithPrevious);
+ deleteUCharVector(stringWithPrevious);
return capitalizedString;
}
- capitalizedString->m_data = newQCharVector(m_length);
+ capitalizedString->m_data = newUCharVector(m_length);
capitalizedString->m_length = m_length;
int32_t endOfWord;
int32_t startOfWord = ubrk_first(boundary);
for (endOfWord = ubrk_next(boundary); endOfWord != UBRK_DONE; startOfWord = endOfWord, endOfWord = ubrk_next(boundary)) {
if (startOfWord != 0) // Ignore first char of previous string
- capitalizedString->m_data[startOfWord - 1] = stringWithPrevious[startOfWord].upper();
+ capitalizedString->m_data[startOfWord - 1] = u_totitle(stringWithPrevious[startOfWord]);
for (int i = startOfWord + 1; i < endOfWord; i++)
capitalizedString->m_data[i - 1] = stringWithPrevious[i];
}
- deleteQCharVector(stringWithPrevious);
+ deleteUCharVector(stringWithPrevious);
return capitalizedString;
}
unsigned i = 0;
// Allow leading spaces.
- for (; i != m_length; ++i) {
- if (!m_data[i].isSpace())
+ for (; i != m_length; ++i)
+ if (!QChar(m_data[i]).isSpace())
break;
- }
// Allow sign.
if (i != m_length && (m_data[i] == '+' || m_data[i] == '-'))
++i;
// Allow digits.
- for (; i != m_length; ++i) {
- if (!m_data[i].isDigit())
+ for (; i != m_length; ++i)
+ if (!u_isdigit(m_data[i]))
break;
- }
- return QConstString(m_data, i).string().toInt(ok);
+ return QConstString(reinterpret_cast<const QChar*>(m_data), i).string().toInt(ok);
}
-static bool equal(const QChar* a, const char* b, int m_length)
+static bool equal(const UChar* a, const char* b, int length)
{
- ASSERT(m_length >= 0);
- while (m_length--) {
- if (*a != *b)
+ ASSERT(length >= 0);
+ while (length--) {
+ unsigned char bc = *b++;
+ if (*a++ != bc)
return false;
- a++; b++;
}
return true;
}
-static bool equalCaseInsensitive(const QChar* a, const char* b, int m_length)
+static bool equalIgnoringCase(const UChar* a, const char* b, int length)
{
- ASSERT(m_length >= 0);
- while (m_length--) {
- if (tolower(a->unicode()) != tolower(*b))
+ ASSERT(length >= 0);
+ while (length--) {
+ unsigned char bc = *b++;
+ if (u_foldCase(*a++, U_FOLD_CASE_DEFAULT) != u_foldCase(bc, U_FOLD_CASE_DEFAULT))
return false;
- a++; b++;
}
return true;
}
-static bool equalCaseInsensitive(const QChar* a, const QChar* b, int m_length)
+static inline bool equalIgnoringCase(const UChar* a, const UChar* b, int length)
{
- ASSERT(m_length >= 0);
- while (m_length--) {
- if (tolower(a->unicode()) != tolower(b->unicode()))
- return false;
- a++; b++;
- }
- return true;
+ ASSERT(length >= 0);
+ return u_memcasecmp(a, b, length, U_FOLD_CASE_DEFAULT) == 0;
}
// This function should be as fast as possible, every little bit helps.
const char* chsPlusOne = chs + 1;
int chsLengthMinusOne = chsLength - 1;
- const QChar* ptr = m_data + index - 1;
+ const UChar* ptr = m_data + index - 1;
if (caseSensitive) {
- QChar c = *chs;
+ UChar c = *chs;
do {
if (*++ptr == c && equal(ptr + 1, chsPlusOne, chsLengthMinusOne))
return m_length - chsLength - n + 1;
} while (--n);
} else {
- int lc = tolower((unsigned char)*chs);
+ UChar lc = u_foldCase(*chs, U_FOLD_CASE_DEFAULT);
do {
- if (tolower((++ptr)->unicode()) == lc && equalCaseInsensitive(ptr + 1, chsPlusOne, chsLengthMinusOne))
+ if (u_foldCase(*++ptr, U_FOLD_CASE_DEFAULT) == lc
+ && equalIgnoringCase(ptr + 1, chsPlusOne, chsLengthMinusOne))
return m_length - chsLength - n + 1;
} while (--n);
}
return -1;
}
-int StringImpl::find(const QChar c, int start) const
+int StringImpl::find(const UChar c, int start) const
{
unsigned int index = start;
if (index >= m_length )
a part of this DeprecatedString. Only if that matches, we call memcmp
or ucstrnicmp.
- The hash value of a string is the sum of the cells of its
- QChars.
+ The hash value of a string is the sum of its characters.
*/
ASSERT(str);
if (index < 0)
if (delta < 0)
return -1;
- const QChar* uthis = m_data + index;
- const QChar* ustr = str->m_data;
+ const UChar* uthis = m_data + index;
+ const UChar* ustr = str->m_data;
unsigned hthis = 0;
unsigned hstr = 0;
if (caseSensitive) {
for (int i = 0; i < lstr; i++) {
- hthis += uthis[i].unicode();
- hstr += ustr[i].unicode();
+ hthis += uthis[i];
+ hstr += ustr[i];
}
int i = 0;
while (1) {
- if (hthis == hstr && memcmp(uthis + i, ustr, lstr * sizeof(QChar)) == 0)
+ if (hthis == hstr && memcmp(uthis + i, ustr, lstr * sizeof(UChar)) == 0)
return index + i;
if (i == delta)
return -1;
- hthis += uthis[i + lstr].unicode();
- hthis -= uthis[i].unicode();
+ hthis += uthis[i + lstr];
+ hthis -= uthis[i];
i++;
}
} else {
for (int i = 0; i < lstr; i++ ) {
- hthis += tolower(uthis[i].unicode());
- hstr += tolower(ustr[i].unicode());
+ hthis += tolower(uthis[i]);
+ hstr += tolower(ustr[i]);
}
int i = 0;
while (1) {
- if (hthis == hstr && equalCaseInsensitive(uthis + i, ustr, lstr))
+ if (hthis == hstr && equalIgnoringCase(uthis + i, ustr, lstr))
return index + i;
if (i == delta)
return -1;
- hthis += tolower(uthis[i + lstr].unicode());
- hthis -= tolower(uthis[i].unicode());
+ hthis += tolower(uthis[i + lstr]);
+ hthis -= tolower(uthis[i]);
i++;
}
}
return false;
}
-StringImpl* StringImpl::replace(QChar oldC, QChar newC)
+StringImpl* StringImpl::replace(UChar oldC, UChar newC)
{
if (oldC == newC)
return this;
StringImpl* c = new StringImpl;
- c->m_data = newQCharVector(m_length);
+ c->m_data = newUCharVector(m_length);
c->m_length = m_length;
for (i = 0; i != m_length; ++i) {
- QChar ch = m_data[i];
+ UChar ch = m_data[i];
if (ch == oldC)
ch = newC;
c->m_data[i] = ch;
return m_data;
}
-StringImpl* StringImpl::replace(QChar pattern, const StringImpl* str)
+StringImpl* StringImpl::replace(UChar pattern, const StringImpl* str)
{
int slen = str ? str->length() : 0;
int index = 0;
return !a;
unsigned length = a->length();
- const QChar* as = a->unicode();
+ const UChar* as = a->characters();
for (unsigned i = 0; i != length; ++i) {
- char c = b[i];
- if (!c)
+ unsigned char bc = b[i];
+ if (!bc)
return false;
- if (as[i] != c)
+ if (as[i] != bc)
return false;
}
return !b[length];
}
-bool equal(const char* a, const StringImpl* b)
-{
- if (!a)
- return !b;
- if (!b)
- return !a;
-
- unsigned length = b->length();
- const QChar* bs = b->unicode();
- for (unsigned i = 0; i != length; ++i) {
- char c = a[i];
- if (!c)
- return false;
- if (c != bs[i])
- return false;
- }
-
- return !a[length];
-}
-
bool equalIgnoringCase(const StringImpl* a, const StringImpl* b)
{
return CaseInsensitiveHash::equal(a, b);
return !a;
unsigned length = a->length();
- const QChar* as = a->unicode();
+ const UChar* as = a->characters();
+
+ // Do a faster loop for the case where it's all ASCII.
+ UChar ored = 0;
+ bool equal = true;
for (unsigned i = 0; i != length; ++i) {
- char c = b[i];
- if (!c)
- return false;
- if (as[i].lower() != QChar(c).lower())
+ unsigned char bc = b[i];
+ if (!bc)
return false;
+ UChar ac = as[i];
+ ored |= ac;
+ equal &= tolower(ac) == tolower(bc);
}
- return !b[length];
-}
-
-bool equalIgnoringCase(const char* a, const StringImpl* b)
-{
- if (!a)
- return !b;
- if (!b)
- return !a;
-
- unsigned length = b->length();
- const QChar* bs = b->unicode();
- for (unsigned i = 0; i != length; ++i) {
- char c = a[i];
- if (!c)
- return false;
- if (QChar(c).lower() != bs[i].lower())
- return false;
+ if (ored & ~0x7F) {
+ equal = true;
+ for (unsigned i = 0; i != length; ++i) {
+ unsigned char bc = b[i];
+ equal &= u_foldCase(as[i], U_FOLD_CASE_DEFAULT) == u_foldCase(bc, U_FOLD_CASE_DEFAULT);
+ }
}
- return !a[length];
+ return equal && !b[length];
}
// Golden ratio - arbitrary start value to avoid mapping all 0's to all 0's
// Paul Hsieh's SuperFastHash
// http://www.azillionmonkeys.com/qed/hash.html
-unsigned StringImpl::computeHash(const QChar* m_data, unsigned len)
+unsigned StringImpl::computeHash(const UChar* m_data, unsigned len)
{
unsigned m_length = len;
uint32_t hash = PHI;
// Main loop
for (; m_length > 0; m_length--) {
- hash += m_data[0].unicode();
- tmp = (m_data[1].unicode() << 11) ^ hash;
+ hash += m_data[0];
+ tmp = (m_data[1] << 11) ^ hash;
hash = (hash << 16) ^ tmp;
m_data += 2;
hash += hash >> 11;
// Handle end case
if (rem) {
- hash += m_data[0].unicode();
+ hash += m_data[0];
hash ^= hash << 11;
hash += hash >> 17;
}
char* buffer = new char[m_length + 1];
char* p = buffer;
for (unsigned i = 0; i != m_length; ++i) {
- unsigned short c = m_data[i].unicode();
+ UChar c = m_data[i];
if (c >= 0x20 && c < 0x7F)
*p++ = c;
else
StringImpl::StringImpl(const Identifier& str)
{
- initWithQChar(reinterpret_cast<const QChar*>(str.data()), str.size());
+ init(reinterpret_cast<const UChar*>(str.data()), str.size());
}
StringImpl::StringImpl(const UString& str)
{
- initWithQChar(reinterpret_cast<const QChar*>(str.data()), str.size());
+ init(reinterpret_cast<const UChar*>(str.data()), str.size());
}
} // namespace WebCore
#ifndef StringImpl_h
#define StringImpl_h
-#include "DeprecatedString.h"
+#include "Shared.h"
+#include <kjs/identifier.h>
#include <wtf/Forward.h>
#include <wtf/Noncopyable.h>
+#include <unicode/umachine.h>
#include <limits.h>
#if __OBJC__
@class NSString;
#endif
+class DeprecatedString;
+
namespace WebCore {
class AtomicString;
-struct QCharBufferTranslator;
+struct UCharBufferTranslator;
struct CStringTranslator;
struct Length;
-class StringImpl : public Shared<StringImpl>, Noncopyable
-{
+class StringImpl : public Shared<StringImpl>, Noncopyable {
private:
struct WithOneRef { };
StringImpl(WithOneRef) : m_length(0), m_data(0), m_hash(0), m_inTable(false) { ref(); }
- void initWithChar(const char*, unsigned len);
- void initWithQChar(const QChar*, unsigned len);
+ void init(const char*, unsigned len);
+ void init(const UChar*, unsigned len);
protected:
StringImpl() : m_length(0), m_data(0), m_hash(0), m_inTable(false) { }
public:
- StringImpl(const DeprecatedString&);
+ StringImpl(const UChar*, unsigned len);
+ StringImpl(const char*, unsigned len);
+ StringImpl(const char*);
StringImpl(const KJS::Identifier&);
StringImpl(const KJS::UString&);
- StringImpl(const QChar*, unsigned len);
- StringImpl(const char*);
- StringImpl(const char*, unsigned len);
~StringImpl();
- const QChar* unicode() const { return m_data; }
+ const UChar* characters() const { return m_data; }
unsigned length() const { return m_length; }
unsigned hash() const { if (m_hash == 0) m_hash = computeHash(m_data, m_length); return m_hash; }
- static unsigned computeHash(const QChar*, unsigned len);
+ static unsigned computeHash(const UChar*, unsigned len);
static unsigned computeHash(const char*);
void append(const StringImpl*);
void insert(const StringImpl*, unsigned pos);
void truncate(int len);
void remove(unsigned pos, int len = 1);
-
+
StringImpl* split(unsigned pos);
StringImpl* copy() const { return new StringImpl(m_data, m_length); }
StringImpl* substring(unsigned pos, unsigned len = UINT_MAX);
- const QChar& operator[] (int pos) const { return m_data[pos]; }
+ UChar operator[](int pos) const { return m_data[pos]; }
Length toLength() const;
-
+
bool containsOnlyWhitespace() const;
bool containsOnlyWhitespace(unsigned from, unsigned len) const;
-
+
// ignores trailing garbage, unlike DeprecatedString
int toInt(bool* ok = 0) const;
bool isLower() const;
StringImpl* lower() const;
StringImpl* upper() const;
- StringImpl* capitalize(QChar previous) const;
+ StringImpl* capitalize(UChar previousCharacter) const;
+ StringImpl* foldCase() const;
int find(const char*, int index = 0, bool caseSensitive = true) const;
- int find(QChar, int index = 0) const;
+ int find(UChar, int index = 0) const;
int find(const StringImpl*, int index, bool caseSensitive = true) const;
bool startsWith(const StringImpl* m_data, bool caseSensitive = true) const { return find(m_data, 0, caseSensitive) == 0; }
bool endsWith(const StringImpl*, bool caseSensitive = true) const;
// Does not modify the string.
- StringImpl* replace(QChar, QChar);
- StringImpl* replace(QChar a, const StringImpl* b);
+ StringImpl* replace(UChar, UChar);
+ StringImpl* replace(UChar, const StringImpl*);
StringImpl* replace(unsigned index, unsigned len, const StringImpl*);
static StringImpl* empty();
operator NSString*() const;
#endif
+ StringImpl(const DeprecatedString&);
+
private:
unsigned m_length;
- QChar* m_data;
+ UChar* m_data;
friend class AtomicString;
- friend struct QCharBufferTranslator;
+ friend struct UCharBufferTranslator;
friend struct CStringTranslator;
mutable unsigned m_hash;
bool equal(const StringImpl*, const StringImpl*);
bool equal(const StringImpl*, const char*);
-bool equal(const char*, const StringImpl*);
+inline bool equal(const char* a, const StringImpl* b) { return equal(b, a); }
bool equalIgnoringCase(const StringImpl*, const StringImpl*);
bool equalIgnoringCase(const StringImpl*, const char*);
-bool equalIgnoringCase(const char*, const StringImpl*);
+inline bool equalIgnoringCase(const char* a, const StringImpl* b) { return equalIgnoringCase(b, a); }
}
#ifndef TextBoundaries_h
#define TextBoundaries_h
-// FIXME: Change clients to use ICU and remove these functions.
+#include <unicode/umachine.h>
-class QChar;
+// FIXME: Change clients to use ICU and remove these functions.
namespace WebCore {
- void findWordBoundary(const QChar*, int len, int position, int *start, int *end);
- int findNextWordFromIndex(const QChar*, int len, int position, bool forward);
+ void findWordBoundary(const UChar*, int len, int position, int *start, int *end);
+ int findNextWordFromIndex(const UChar*, int len, int position, bool forward);
- void findSentenceBoundary(const QChar*, int len, int position, int *start, int *end);
- int findNextSentenceFromIndex(const QChar*, int len, int position, bool forward);
+ void findSentenceBoundary(const UChar*, int len, int position, int *start, int *end);
+ int findNextSentenceFromIndex(const UChar*, int len, int position, bool forward);
}
{
return charsetNameFromTextEncodingID(m_encodingID);
}
-
-QChar TextEncoding::backslashAsCurrencySymbol() const
+UChar TextEncoding::backslashAsCurrencySymbol() const
{
if (m_flags & BackslashIsYen)
return 0x00A5; // yen sign
// until then, we change the backslash into a yen sign.
// Encoding will change the yen sign back into a backslash.
DeprecatedString copy = qcs;
- copy.replace(QChar('\\'), backslashAsCurrencySymbol());
+ copy.replace('\\', backslashAsCurrencySymbol());
UErrorCode err = U_ZERO_ERROR;
UConverter* conv = getConverter(encoding, &err);
bool usesVisualOrdering() const { return m_flags & VisualOrdering; }
bool isJapanese() const { return m_flags & IsJapanese; }
- QChar backslashAsCurrencySymbol() const;
+ UChar backslashAsCurrencySymbol() const;
DeprecatedCString fromUnicode(const DeprecatedString&, bool allowEntities = false) const;
families = CFDictionaryCreateMutable(NULL, 0, &CFDictionaryFamilyKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
m_CFFamily = (CFStringRef)CFDictionaryGetValue(families, m_family.impl());
if (!m_CFFamily) {
- m_CFFamily = CFStringCreateWithCharacters(0, (const UniChar *)m_family.unicode(), m_family.length());
+ m_CFFamily = CFStringCreateWithCharacters(0, m_family.characters(), m_family.length());
CFDictionarySetValue(families, m_family.impl(), m_CFFamily);
CFRelease(m_CFFamily);
}
#import "IntRect.h"
+using namespace std;
+
namespace WebCore {
FontFallbackList::FontFallbackList()
}
IntRect Font::selectionRectForText(const IntPoint& point, int h, int tabWidth, int xpos,
- const QChar* str, int slen, int pos, int l, int toAdd,
+ const UChar* str, int slen, int pos, int l, int toAdd,
bool rtl, bool visuallyOrdered, int from, int to) const
{
assert(m_fontList);
- int len = std::min(slen - pos, l);
+ int len = min(slen - pos, l);
CREATE_FAMILY_ARRAY(fontDescription(), families);
to = len;
WebCoreTextRun run;
- WebCoreInitializeTextRun(&run, (const UniChar *)(str+pos), len, from, to);
+ WebCoreInitializeTextRun(&run, str + pos, len, from, to);
WebCoreTextStyle style;
WebCoreInitializeEmptyTextStyle(&style);
style.rtl = rtl;
return enclosingIntRect(m_fontList->primaryFont(fontDescription())->selectionRectForRun(&run, &style, &geometry));
}
-void Font::drawText(GraphicsContext* context, const IntPoint& point, int tabWidth, int xpos, const QChar* str, int len, int from, int to,
+void Font::drawText(GraphicsContext* context, const IntPoint& point, int tabWidth, int xpos, const UChar* str, int len, int from, int to,
int toAdd, TextDirection d, bool visuallyOrdered) const
{
// Avoid allocations, use stack array to pass font families. Normally these
to = len;
WebCoreTextRun run;
- WebCoreInitializeTextRun(&run, (const UniChar *)str, len, from, to);
+ WebCoreInitializeTextRun(&run, str, len, from, to);
WebCoreTextStyle style;
WebCoreInitializeEmptyTextStyle(&style);
style.textColor = nsColor(context->pen().color());
m_fontList->primaryFont(fontDescription())->drawRun(&run, &style, &geometry);
}
-void Font::drawHighlightForText(GraphicsContext* context, const IntPoint& point, int h, int tabWidth, int xpos, const QChar* str,
+void Font::drawHighlightForText(GraphicsContext* context, const IntPoint& point, int h, int tabWidth, int xpos, const UChar* str,
int len, int from, int to, int toAdd,
TextDirection d, bool visuallyOrdered, const Color& backgroundColor) const
{
to = len;
WebCoreTextRun run;
- WebCoreInitializeTextRun(&run, (const UniChar *)str, len, from, to);
+ WebCoreInitializeTextRun(&run, str, len, from, to);
WebCoreTextStyle style;
WebCoreInitializeEmptyTextStyle(&style);
style.textColor = nsColor(context->pen().color());
return m_fontList->primaryFont(fontDescription())->misspellingLineThickness();
}
-float Font::floatWidth(const QChar* uchars, int slen, int pos, int len, int tabWidth, int xpos, bool runRounding) const
+float Font::floatWidth(const UChar* uchars, int slen, int pos, int len, int tabWidth, int xpos, bool runRounding) const
{
assert(m_fontList);
CREATE_FAMILY_ARRAY(fontDescription(), families);
WebCoreTextRun run;
- WebCoreInitializeTextRun(&run, (const UniChar *)uchars, slen, pos, pos+len);
+ WebCoreInitializeTextRun(&run, uchars, slen, pos, pos + len);
WebCoreTextStyle style;
WebCoreInitializeEmptyTextStyle(&style);
return m_fontList->primaryFont(fontDescription())->floatWidthForRun(&run, &style);
}
-int Font::checkSelectionPoint(const QChar* s, int slen, int pos, int len, int toAdd, int tabWidth, int xpos, int x, TextDirection d, bool visuallyOrdered, bool includePartialGlyphs) const
+int Font::checkSelectionPoint(const UChar* s, int slen, int pos, int len, int toAdd, int tabWidth, int xpos, int x, TextDirection d, bool visuallyOrdered, bool includePartialGlyphs) const
{
assert(m_fontList);
CREATE_FAMILY_ARRAY(fontDescription(), families);
WebCoreTextRun run;
- WebCoreInitializeTextRun(&run, (const UniChar *)(s+pos), std::min(slen - pos, len), 0, len);
+ WebCoreInitializeTextRun(&run, s + pos, min(slen - pos, len), 0, len);
WebCoreTextStyle style;
WebCoreInitializeEmptyTextStyle(&style);
namespace WebCore {
-void findWordBoundary(const QChar* chars, int len, int position, int* start, int* end)
+void findWordBoundary(const UChar* chars, int len, int position, int* start, int* end)
{
- NSString* string = [[NSString alloc] initWithCharactersNoCopy:const_cast<unichar*>(reinterpret_cast<const unichar*>(chars))
+ NSString* string = [[NSString alloc] initWithCharactersNoCopy:const_cast<unichar*>(chars)
length:len freeWhenDone:NO];
NSAttributedString* attr = [[NSAttributedString alloc] initWithString:string];
NSRange range = [attr doubleClickAtIndex:(position >= len) ? len - 1 : position];
*end = range.location + range.length;
}
-int findNextWordFromIndex(const QChar* chars, int len, int position, bool forward)
+int findNextWordFromIndex(const UChar* chars, int len, int position, bool forward)
{
- NSString* string = [[NSString alloc] initWithCharactersNoCopy:const_cast<unichar*>(reinterpret_cast<const unichar*>(chars))
+ NSString* string = [[NSString alloc] initWithCharactersNoCopy:const_cast<unichar*>(chars)
length:len freeWhenDone:NO];
NSAttributedString* attr = [[NSAttributedString alloc] initWithString:string];
int result = [attr nextWordFromIndex:position forward:forward];
return localeString;
}
-void findSentenceBoundary(const QChar* chars, int len, int position, int* start, int* end)
+void findSentenceBoundary(const UChar* chars, int len, int position, int* start, int* end)
{
int startPos = 0;
int endPos = 0;
UErrorCode status = U_ZERO_ERROR;
- UBreakIterator* boundary = ubrk_open(UBRK_SENTENCE, currentTextBreakLocaleID(),
- const_cast<unichar*>(reinterpret_cast<const unichar*>(chars)), len, &status);
+ UBreakIterator* boundary = ubrk_open(UBRK_SENTENCE, currentTextBreakLocaleID(), chars, len, &status);
if (boundary && U_SUCCESS(status)) {
startPos = ubrk_preceding(boundary, position);
if (startPos == UBRK_DONE) {
*end = endPos;
}
-int findNextSentenceFromIndex(const QChar* chars, int len, int position, bool forward)
+int findNextSentenceFromIndex(const UChar* chars, int len, int position, bool forward)
{
int pos = 0;
UErrorCode status = U_ZERO_ERROR;
- UBreakIterator* boundary = ubrk_open(UBRK_SENTENCE, currentTextBreakLocaleID(),
- const_cast<unichar*>(reinterpret_cast<const unichar*>(chars)), len, &status);
+ UBreakIterator* boundary = ubrk_open(UBRK_SENTENCE, currentTextBreakLocaleID(), chars, len, &status);
if (boundary && U_SUCCESS(status)) {
if (forward) {
pos = ubrk_following(boundary, position);
// FIXME: Since there's no "force ASCII range" mode in CFString, we change the backslash into a yen sign.
// Encoding will change the yen sign back into a backslash.
DeprecatedString copy = qcs;
- copy.replace(QChar('\\'), backslashAsCurrencySymbol());
+ copy.replace('\\', backslashAsCurrencySymbol());
CFStringRef cfs = copy.getCFString();
CFMutableStringRef cfms = CFStringCreateMutableCopy(0, 0, cfs); // in rare cases, normalization can make the string longer, thus no limit on its length
CFStringNormalize(cfms, kCFStringNormalizationFormC);
const Font *f = textObj->font(m_firstLine);
IntRect r = f->selectionRectForText(IntPoint(tx + m_x, ty + selTop), selHeight, textObj->tabWidth(), textPos(),
- textObj->str->unicode(), textObj->str->length(), m_start, m_len,
+ textObj->str->characters(), textObj->str->length(), m_start, m_len,
m_toAdd, m_reversed, m_dirOverride, sPos, ePos);
if (r.x() > tx + m_x + m_width)
r.setWidth(0);
if (m_truncation != cNoTruncation)
endPoint = m_truncation - m_start;
i.p->drawText(IntPoint(m_x + tx, m_y + ty + m_baseline), textObject()->tabWidth(), textPos(),
- textObject()->string()->unicode(), textObject()->string()->length(), m_start, endPoint,
+ textObject()->string()->characters(), textObject()->string()->length(), m_start, endPoint,
m_toAdd, m_reversed ? RTL : LTR, m_dirOverride || styleToUse->visuallyOrdered());
} else {
int sPos, ePos;
// paint only the text that is not selected
if (sPos >= ePos)
i.p->drawText(IntPoint(m_x + tx, m_y + ty + m_baseline), textObject()->tabWidth(), textPos(),
- textObject()->string()->unicode(), textObject()->string()->length(), m_start, m_len,
+ textObject()->string()->characters(), textObject()->string()->length(), m_start, m_len,
m_toAdd, m_reversed ? RTL : LTR, m_dirOverride || styleToUse->visuallyOrdered());
else {
if (sPos - 1 >= 0)
i.p->drawText(IntPoint(m_x + tx, m_y + ty + m_baseline), textObject()->tabWidth(), textPos(),
- textObject()->string()->unicode(), textObject()->string()->length(), m_start, m_len,
+ textObject()->string()->characters(), textObject()->string()->length(), m_start, m_len,
m_toAdd, m_reversed ? RTL : LTR, m_dirOverride || styleToUse->visuallyOrdered(), 0, sPos);
if (ePos < m_start + m_len)
i.p->drawText(IntPoint(m_x + tx, m_y + ty + m_baseline), textObject()->tabWidth(), textPos(),
- textObject()->string()->unicode(), textObject()->string()->length(), m_start, m_len,
+ textObject()->string()->characters(), textObject()->string()->length(), m_start, m_len,
m_toAdd, m_reversed ? RTL : LTR, m_dirOverride || styleToUse->visuallyOrdered(), ePos, -1);
}
}
selectionTextShadow->blur,
selectionTextShadow->color);
i.p->drawText(IntPoint(m_x + tx, m_y + ty + m_baseline), textObject()->tabWidth(), textPos(),
- textObject()->string()->unicode(), textObject()->string()->length(), m_start, m_len,
+ textObject()->string()->characters(), textObject()->string()->length(), m_start, m_len,
m_toAdd, m_reversed ? RTL : LTR, m_dirOverride || styleToUse->visuallyOrdered(), sPos, ePos);
if (selectionTextShadow)
i.p->clearShadow();
int h = r->selectionHeight();
p->addClip(IntRect(m_x + tx, y + ty, m_width, h));
p->drawHighlightForText(IntPoint(m_x + tx, y + ty), h, textObject()->tabWidth(), textPos(),
- textObject()->str->unicode(), textObject()->str->length(), m_start, m_len,
+ textObject()->str->characters(), textObject()->str->length(), m_start, m_len,
m_toAdd, m_reversed ? RTL : LTR, m_dirOverride || style->visuallyOrdered(), sPos, ePos, c);
p->restore();
}
int y = r->selectionTop();
int h = r->selectionHeight();
p->drawHighlightForText(IntPoint(m_x + tx, y + ty), h, textObject()->tabWidth(), textPos(),
- textObject()->str->unicode(), textObject()->str->length(), m_start, m_len,
+ textObject()->str->characters(), textObject()->str->length(), m_start, m_len,
m_toAdd, m_reversed ? RTL : LTR, m_dirOverride || style->visuallyOrdered(), sPos, ePos, c);
p->restore();
}
int ePos = min(marker.endOffset - m_start, (unsigned)m_len);
pt->drawHighlightForText(IntPoint(m_x + _tx, y + _ty), h, textObject()->tabWidth(), textPos(),
- textObject()->str->unicode(), textObject()->str->length(), m_start, m_len,
+ textObject()->str->characters(), textObject()->str->length(), m_start, m_len,
m_toAdd, m_reversed ? RTL : LTR, m_dirOverride || style->visuallyOrdered(), sPos, ePos, yellow);
pt->restore();
}
RenderText* text = static_cast<RenderText*>(m_object);
RenderStyle *style = text->style(m_firstLine);
const Font* f = &style->font();
- return f->checkSelectionPoint(text->str->unicode(), text->str->length(), m_start, m_len,
+ return f->checkSelectionPoint(text->str->characters(), text->str->length(), m_start, m_len,
m_toAdd, text->tabWidth(), textPos(), _x - m_x,
m_reversed ? RTL : LTR, m_dirOverride || style->visuallyOrdered(), includePartialGlyphs);
}
int from = m_reversed ? offset - m_start : 0;
int to = m_reversed ? m_len : offset - m_start;
// FIXME: Do we need to add rightBearing here?
- return f->selectionRectForText(IntPoint(m_x, 0), 0, text->tabWidth(), textPos(), text->str->unicode(), text->str->length(), m_start, m_len,
+ return f->selectionRectForText(IntPoint(m_x, 0), 0, text->tabWidth(), textPos(), text->str->characters(), text->str->length(), m_start, m_len,
m_toAdd, m_reversed, m_dirOverride, from, to).right();
}
// Collapse away the trailing space at the end of a block.
RenderText* t = static_cast<RenderText *>(trailingSpaceChild);
const Font *f = t->font(false); // FIXME: Why are we ignoring first-line?
- QChar space[1]; space[0] = ' ';
- int spaceWidth = f->width(space, 1);
+ const UChar space = ' ';
+ int spaceWidth = f->width(&space, 1);
inlineMax -= spaceWidth;
if (inlineMin > inlineMax)
inlineMin = inlineMax;
unsigned int length = 0;
// account for leading spaces and punctuation
- while (length < oldText->length() && ((*oldText)[length].isSpace() || (*oldText)[length].isPunct()))
+ while (length < oldText->length() && (QChar((*oldText)[length]).isSpace() || u_ispunct((*oldText)[length])))
length++;
// account for first letter
RenderBlock* blockChild = static_cast<RenderBlock*>(child);
int lineCount = blockChild->lineCount();
- if (lineCount <= numVisibleLines) continue;
+ if (lineCount <= numVisibleLines)
+ continue;
int newHeight = blockChild->heightForLineCount(numVisibleLines);
- if (newHeight == child->height()) continue;
+ if (newHeight == child->height())
+ continue;
child->setChildNeedsLayout(true);
child->setOverrideSize(newHeight);
child->setOverrideSize(-1);
// FIXME: For now don't support RTL.
- if (style()->direction() != LTR) continue;
+ if (style()->direction() != LTR)
+ continue;
// Get the last line
RootInlineBox* lastLine = blockChild->lineAtIndex(lineCount-1);
- if (!lastLine) continue;
+ if (!lastLine)
+ continue;
// See if the last item is an anchor
InlineBox* anchorBox = lastLine->lastChild();
- if (!anchorBox) continue;
- if (!anchorBox->object()->element()) continue;
- if (!anchorBox->object()->element()->isLink()) continue;
+ if (!anchorBox)
+ continue;
+ if (!anchorBox->object()->element())
+ continue;
+ if (!anchorBox->object()->element()->isLink())
+ continue;
RootInlineBox* lastVisibleLine = blockChild->lineAtIndex(numVisibleLines-1);
- if (!lastVisibleLine) continue;
+ if (!lastVisibleLine)
+ continue;
- const unsigned short ellipsisAndSpace[2] = { 0x2026, ' ' };
+ const UChar ellipsisAndSpace[2] = { 0x2026, ' ' };
static AtomicString ellipsisAndSpaceStr(ellipsisAndSpace, 2);
+
const Font& font = style(numVisibleLines == 1)->font();
- int ellipsisAndSpaceWidth = font.width(const_cast<QChar*>(ellipsisAndSpaceStr.unicode()), 2, 0, 2, 0, 0);
+ int ellipsisAndSpaceWidth = font.width(ellipsisAndSpace, 2, 0, 2, 0, 0);
// Get ellipsis width + " " + anchor width
int totalWidth = ellipsisAndSpaceWidth + anchorBox->width();
RenderBlock* srcBlock = static_cast<RenderBlock*>(lastLine->object());
// FIXME: Directions of src/destBlock could be different from our direction and from one another.
- if (srcBlock->style()->direction() != LTR) continue;
- if (destBlock->style()->direction() != LTR) continue;
+ if (srcBlock->style()->direction() != LTR)
+ continue;
+ if (destBlock->style()->direction() != LTR)
+ continue;
int blockEdge = destBlock->rightOffset(lastVisibleLine->yPos());
if (!lastVisibleLine->canAccommodateEllipsis(true, blockEdge,
// we have an alt and the user meant it (its not a text we invented)
if (!m_altText.isEmpty()) {
const Font& font = style()->font();
- iw = max(iw, min(font.width(m_altText.deprecatedString()), 1024));
+ iw = max(iw, min(font.width(m_altText.characters(), m_altText.length()), 1024));
ih = max(ih, min(font.height(), 256));
}
if (!m_altText.isEmpty()) {
DeprecatedString text = m_altText.deprecatedString();
- text.replace(QChar('\\'), backslashAsCurrencySymbol());
+ text.replace('\\', backslashAsCurrencySymbol());
p->setFont(style()->font());
p->setPen(style()->color());
int ax = _tx + leftBorder + leftPad;
// Only draw the alt text if it'll fit within the content box,
// and only if it fits above the error image.
- int textWidth = font.width(text);
+ int textWidth = font.width(reinterpret_cast<const UChar*>(text.unicode()), text.length());
if (errorPictureDrawn) {
if (usableWidth >= textWidth && font.height() <= imageY)
- p->drawText(IntPoint(ax, ay + ascent), 0, text);
+ p->drawText(IntPoint(ax, ay + ascent), text);
} else if (usableWidth >= textWidth && cHeight >= font.height())
- p->drawText(IntPoint(ax, ay + ascent), 0, text);
+ p->drawText(IntPoint(ax, ay + ascent), text);
}
}
}
return (avoidsFloats() && (style()->width().isAuto() || isHR() || (style()->htmlHacks() && !isTable())));
}
-QChar RenderObject::backslashAsCurrencySymbol() const
+UChar RenderObject::backslashAsCurrencySymbol() const
{
if (Node *node = element())
if (Decoder *decoder = node->document()->decoder())
virtual bool isStretchingChildren() const { return false; }
// Convenience, to avoid repeating the code to dig down to get this.
- QChar backslashAsCurrencySymbol() const;
+ UChar backslashAsCurrencySymbol() const;
virtual int caretMinOffset() const;
virtual int caretMaxOffset() const;
return 0;
status = U_ZERO_ERROR;
- ubrk_setText(iterator, reinterpret_cast<const UChar*>(i->unicode()), i->length(), &status);
+ ubrk_setText(iterator, reinterpret_cast<const UChar*>(i->characters()), i->length(), &status);
if (status != U_ZERO_ERROR)
return 0;
setRenderText();
if (str)
str = str->replace('\\', backslashAsCurrencySymbol());
- KHTMLAssert(!str || !str->length() || str->unicode());
+ KHTMLAssert(!str || !str->length() || str->characters());
}
void RenderText::setStyle(RenderStyle *_style)