[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdelibs/interfaces/ktexteditor
From: Anders Lund <anders () alweb ! dk>
Date: 2004-10-13 17:19:34
Message-ID: 20041013171934.DB5D516C9B () office ! kde ! org
[Download RAW message or body]
CVS commit by alund:
yet better, parse the template string where it is required only
M +77 -68 templateinterface.cpp 1.5
M +3 -3 templateinterface.h 1.6
--- kdelibs/interfaces/ktexteditor/templateinterface.h #1.5:1.6
@@ -46,10 +46,10 @@ class KTEXTEDITOR_EXPORT TemplateInterfa
* Parses @p templateString for macros in the form [$%]{NAME} and finds
* the value corresponding to NAME if any.
- * @param templateString The string containing the macros to expand
- * @param map a map in which the values are placed.
+ * @param map a map with the keys for the macros to expand. keys with a value
+ * are ignored.
* @see insertTemplateText for a list of supported macros
* @return true if all macros was sucessfully expanded
*/
- bool expandMacros( QString templateString, QMap<QString, QString> \
&initialValues, QWidget *parentWindow ); + bool expandMacros( QMap<QString, \
QString> &initialValues, QWidget *parentWindow );
uint templateInterfaceNumber () const;
--- kdelibs/interfaces/ktexteditor/templateinterface.cpp #1.4:1.5
@@ -64,5 +64,5 @@ void TemplateInterface::setTemplateInter
} while(false)
-bool TemplateInterface::expandMacros( QString templateString, QMap<QString, QString> \
&map, QWidget *parentWindow ) +bool TemplateInterface::expandMacros( QMap<QString, \
QString> &map, QWidget *parentWindow ) {
KABC::StdAddressBook *addrBook = 0;
@@ -71,28 +71,9 @@ bool TemplateInterface::expandMacros( QS
QDate date = datetime.date();
QTime time = datetime.time();
- QRegExp rx( "[$%]\\{([a-zA-Z0-9_]+)\\}" );
- rx.setMinimal( true );
- int pos = 0;
- int opos = 0;
- while ( pos >= 0 )
- {
- pos = rx.search( templateString, pos );
-
- if ( pos > -1 )
- {
- if ( ( pos - opos ) > 0 )
- {
- if ( templateString[ pos - 1 ] == '\\' )
+ QMap<QString,QString>::Iterator it;
+ for ( it = map.begin(); it != map.end(); ++it )
{
- pos = opos = pos + 1;
- continue;
- }
- }
-
- QString placeholder = rx.cap( 1 );
- pos += rx.matchedLength();
- opos = pos;
-
+ QString placeholder = it.key();
if ( map[ placeholder ].isEmpty() )
{
@@ -155,5 +136,4 @@ bool TemplateInterface::expandMacros( QS
}
}
- }
return true;
}
@@ -162,5 +142,34 @@ bool TemplateInterface::insertTemplateTe
{
QMap<QString, QString> enhancedInitValues( initialValues );
- return expandMacros( templateString, enhancedInitValues, parentWindow )
+
+ QRegExp rx( "[$%]\\{([a-zA-Z0-9_]+)\\}" );
+ rx.setMinimal( true );
+ int pos = 0;
+ int opos = 0;
+
+ while ( pos >= 0 )
+ {
+ pos = rx.search( templateString, pos );
+
+ if ( pos > -1 )
+ {
+ if ( ( pos - opos ) > 0 )
+ {
+ if ( templateString[ pos - 1 ] == '\\' )
+ {
+ pos = opos = pos + 1;
+ continue;
+ }
+ }
+ QString placeholder = rx.cap( 1 );
+ if ( ! enhancedInitValues.contains( placeholder ) )
+ enhancedInitValues[ placeholder ] = "";
+
+ pos += rx.matchedLength();
+ opos = pos;
+ }
+ }
+
+ return expandMacros( enhancedInitValues, parentWindow )
&& insertTemplateTextImplementation( line, column, templateString, \
enhancedInitValues, parentWindow ); }
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic