Merged KDE 3.0 final code in and:

JavaScriptCore:

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

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

	* JavaScriptCore.pbproj/project.pbxproj: Added nodes2string.cpp.

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

WebCore:

	* src/kdelibs/khtml/rendering/render_text.cpp: (TextSlave::printDecoration):
	Remove some minor gratuitous diffs vs. KDE.

	* src/kdelibs/khtml/rendering/render_text.cpp: (TextSlave::printDecoration):
        Richard updated to reflect changes in KDE.

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

	Fix text to it displays at the right font size.

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

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

	* src/kdelibs/khtml/rendering/font.cpp: (max): New helper.
	(Font::drawText): Simplified implementation for now.
	(Font::width): Simplified implementation for now.
	* src/kwq/KWQColorGroup.mm: Reinstated QCOLOR_GROUP_SIZE.

	* src/kwq/qt/qfontmetrics.h: Removed charWidth and changed _width to take QChar *.
	* src/kwq/KWQFontMetrics.mm: Removed charWidth and changed _width to take QChar *.

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

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

        Merged changes from previous merge pass.

        2002-03-25  Darin Adler  <darin@apple.com>

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

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

        2002-03-25  Darin Adler  <darin@apple.com>

	* src/kdelibs/khtml/rendering/font.cpp: (Font::width): Make it call _width so we
        don't lose the optimization.

	* src/kwq/KWQApplication.mm: (QDesktopWidget::screenNumber): New.
	(QDesktopWidget::screenGeometry): New.
        (QApplication::style): New.
	* src/kwq/KWQColorGroup.mm: (QColorGroup::highlight): New.
	(QColorGroup::highlightedText): New.
	* src/kwq/KWQFont.mm: (QFont::setPixelSize): New.
	* src/kwq/KWQFontMetrics.mm: (QFontMetrics::charWidth): New.
	* src/kwq/KWQKGlobal.mm: (KGlobal::locale): Implement.
        (KLocale::KLocale): New.
	(KLocale::languageList): New.
	* src/kwq/KWQKHTMLPart.mm: (KHTMLPart::sheetUsed): New.
	(KHTMLPart::setSheetUsed): New.
        (KHTMLPart::zoomFactor): New.
	* src/kwq/KWQKHTMLSettings.mm: (KHTMLSettings::mediumFontSize): New.
	* src/kwq/KWQScrollView.mm: (QScrollView::childX): New.
        (QScrollView::childY): New.

	* src/kwq/qt/qapplication.h: style() returns a QStyle &.
	* src/kwq/qt/qpalette.h: Add Highlight and HighlightedText.

        2002-03-24  Darin Adler  <darin@apple.com>

        More compiling. Still won't link.

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

        2002-03-24  Darin Adler  <darin@apple.com>

        Some fixes to get more stuff to compile.

	* src/kdelibs/khtml/ecma/kjs_dom.cpp: (DOMDocument::getValueProperty):
        Don't try to look at the private m_bComplete to display "complete". Just do
        "loading" and "loaded".
        * src/kdelibs/khtml/khtmlpart_p.h: #ifdef this all out for APPLE_CHANGES.
	* src/kdelibs/khtml/rendering/font.cpp: (Font::update): Add an explicit cast to
        int to avoid float -> int warning.
	* src/kdelibs/khtml/rendering/render_table.cpp: (RenderTable::calcColMinMax):
        Add an explicit cast to int to avoid uint compared with int warning.
	* src/kdelibs/khtml/xml/dom_docimpl.cpp: (DocumentImpl::recalcStyleSelector):
        Use sheetUsed() and setSheetUsed() functions on KHTMLPart intead of getting
        at private fields the way the real KDE code does.

        * src/kwq/KWQKHTMLPart.h: Declare zoomFactor(), sheetUsed(), and setSheetUsed().
	* src/kwq/KWQStyle.h: Add PM_DefaultFramWidth as another metric.
	* src/kwq/kdecore/klocale.h: Add languageList().
	* src/kwq/khtml/khtml_settings.h: Add mediumFontSize().
	* src/kwq/qt/qapplication.h: Add style() and QDesktopWidget.
	* src/kwq/qt/qevent.h: Add reason().
	* src/kwq/qt/qfont.h: Add setPixelSize(int).
	* src/kwq/qt/qfontmetrics.h: Add charWidth() and _charWidth() functions.
	* src/kwq/qt/qpainter.h: Add drawText() overload with position parameter.
	* src/kwq/qt/qpalette.h: Add highlight() and highlightedText().
	* src/kwq/qt/qscrollview.h: Add childX() and childY().

	* src/kwq/KWQApplication.mm: Change KWQDesktopWidget to QDesktopWidget.

WebKit:

	* WebView.subproj/IFPreferences.h:
	* WebView.subproj/IFPreferences.mm: (+[IFPreferences load]): Remove the old
	WebKitFontSizes preference.
	(-[IFPreferences mediumFontSize]), (-[IFPreferences setMediumFontSize:]): New.

	* WebView.subproj/IFWebView.mm: (-[IFWebView reapplyStyles]): Call
	updateStyleSelector() instead of recalcStyle().

        Merged changes from previous merge branch.

        2002-03-25  Darin Adler  <darin@apple.com>

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

WebBrowser:

	* Preferences.subproj/TextPreferences.m: (-[TextPreferences defaultFontSize]),
	(-[TextPreferences setDefaultFontSize:]): Just get and set the new mediumFontSize
	preference rather than doing the whole fontSizes preference dance.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@1024 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/kjs/string_object.cpp b/JavaScriptCore/kjs/string_object.cpp
index 5f47f0f..c7c9cf1 100644
--- a/JavaScriptCore/kjs/string_object.cpp
+++ b/JavaScriptCore/kjs/string_object.cpp
@@ -202,17 +202,13 @@
       RegExpImp* imp = static_cast<RegExpImp *>( a0.toObject(exec).imp() );
       reg = imp->regExp();
     }
-    else if (a0.isA(StringType))
-    {
-      reg = new RegExp(a0.toString(exec), RegExp::None);
-    }
     else
-    {
-#ifndef NDEBUG
-      printf("KJS: Match/Search. Argument is not a RegExp nor a String - returning Undefined\n");
-#endif
-      result = Undefined();
-      break;
+    { /*
+       *  ECMA 15.5.4.12 String.prototype.search (regexp)
+       *  If regexp is not an object whose [[Class]] property is "RegExp", it is
+       *  replaced with the result of the expression new RegExp(regexp).
+       */
+      reg = new RegExp(a0.toString(exec), RegExp::None);
     }
     RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->interpreter()->builtinRegExp().imp());
     int **ovector = regExpObj->registerRegexp( reg, u );
@@ -240,16 +236,34 @@
         global = true;
 
       RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->interpreter()->builtinRegExp().imp());
-      int **ovector = regExpObj->registerRegexp( reg, u );
       int lastIndex = 0;
       u3 = a1.toString(exec); // replacement string
       // This is either a loop (if global is set) or a one-way (if not).
       do {
+        int **ovector = regExpObj->registerRegexp( reg, u );
         UString mstr = reg->match(u, lastIndex, &pos, ovector);
         len = mstr.size();
-        lastIndex = pos + u3.size();
+        UString rstr(u3);
+        bool ok;
+        // check if u3 matches $1 or $2 etc
+        for (int i = 0; (i = rstr.find(UString("$"), i)) != -1; i++) {
+          if (i+1<rstr.size() && rstr[i+1] == '$') {  // "$$" -> "$"
+            rstr = rstr.substr(0,i) + "$" + rstr.substr(i+2);
+            continue;
+          }
+          // Assume number part is one char exactly
+          unsigned long pos = rstr.substr(i+1,1).toULong(&ok);
+          if (ok && pos <= (unsigned)reg->subPatterns()) {
+            rstr = rstr.substr(0,i)
+                      + u.substr((*ovector)[2*pos],
+                                     (*ovector)[2*pos+1]-(*ovector)[2*pos])
+                      + rstr.substr(i+2);
+            i += (*ovector)[2*pos+1]-(*ovector)[2*pos] - 1; // -1 offsets i++
+          }
+        }
+        lastIndex = pos + rstr.size();
         if ( pos != -1 )
-          u = u.substr(0, pos) + u3 + u.substr(pos + len);
+          u = u.substr(0, pos) + rstr + u.substr(pos + len);
         //fprintf(stderr,"pos=%d,len=%d,lastIndex=%d,u=%s\n",pos,len,lastIndex,u.ascii());
       } while ( global && pos != -1 );
 
@@ -320,7 +334,7 @@
 	  i++;
 	}
       }
-      delete ovector;
+      delete [] ovector;
     } else if (a0.type() != UndefinedType) {
       u2 = a0.toString(exec);
       if (u2.isEmpty()) {