Mercurial > hg > easyhg-kdiff3
comparison kdiff3/src/kreplacements/kreplacements.cpp @ 58:8af4bb9d9a5a
Version 0.9.83
author | joachim99 |
---|---|
date | Sun, 07 Mar 2004 09:59:09 +0000 |
parents | 32d5cbf9db71 |
children | efe33e938730 |
comparison
equal
deleted
inserted
replaced
57:023fbd76c1e3 | 58:8af4bb9d9a5a |
---|---|
139 } | 139 } |
140 | 140 |
141 int KMessageBox::warningYesNo( QWidget* parent, const QString& text, const QString& caption, | 141 int KMessageBox::warningYesNo( QWidget* parent, const QString& text, const QString& caption, |
142 const QString& button1, const QString& button2 ) | 142 const QString& button1, const QString& button2 ) |
143 { | 143 { |
144 return 0 == QMessageBox::warning( parent, caption, text, button1, button2 ) ? Yes : No; | 144 return 0 == QMessageBox::warning( parent, caption, text, button1, button2, QString::null, 1, 1 ) ? Yes : No; |
145 } | 145 } |
146 | 146 |
147 int KMessageBox::warningYesNoCancel( QWidget* parent, const QString& text, const QString& caption, | 147 int KMessageBox::warningYesNoCancel( QWidget* parent, const QString& text, const QString& caption, |
148 const QString& button1, const QString& button2 ) | 148 const QString& button1, const QString& button2 ) |
149 { | 149 { |
417 | 417 |
418 void KConfig::setGroup(const QString&) | 418 void KConfig::setGroup(const QString&) |
419 { | 419 { |
420 } | 420 } |
421 | 421 |
422 // safeStringJoin and safeStringSplit allow to convert a stringlist into a string and back | |
423 // safely, even if the individual strings in the list contain the separator character. | |
424 static QString safeStringJoin(const QStringList& sl, char sepChar=',', char metaChar='\\' ) | |
425 { | |
426 // Join the strings in the list, using the separator ',' | |
427 // If a string contains the separator character, it will be replaced with "\,". | |
428 // Any occurances of "\" (one backslash) will be replaced with "\\" (2 backslashes) | |
429 | |
430 assert(sepChar!=metaChar); | |
431 | |
432 QString sep; | |
433 sep += sepChar; | |
434 QString meta; | |
435 meta += metaChar; | |
436 | |
437 QString safeString; | |
438 | |
439 QStringList::const_iterator i; | |
440 for (i=sl.begin(); i!=sl.end(); ++i) | |
441 { | |
442 QString s = *i; | |
443 s.replace(meta, meta+meta); // "\" -> "\\" | |
444 s.replace(sep, meta+sep); // "," -> "\," | |
445 if ( i==sl.begin() ) | |
446 safeString = s; | |
447 else | |
448 safeString += sep + s; | |
449 } | |
450 return safeString; | |
451 } | |
452 | |
453 // Split a string that was joined with safeStringJoin | |
454 static QStringList safeStringSplit(const QString& s, char sepChar=',', char metaChar='\\' ) | |
455 { | |
456 assert(sepChar!=metaChar); | |
457 QStringList sl; | |
458 // Miniparser | |
459 int i=0; | |
460 int len=s.length(); | |
461 QString b; | |
462 for(i=0;i<len;++i) | |
463 { | |
464 if ( i+1<len && s[i]==metaChar && s[i+1]==metaChar ){ b+=metaChar; ++i; } | |
465 else if ( i+1<len && s[i]==metaChar && s[i+1]==sepChar ){ b+=sepChar; ++i; } | |
466 else if ( s[i]==sepChar ) // real separator | |
467 { | |
468 sl.push_back(b); | |
469 b=""; | |
470 } | |
471 else { b+=s[i]; } | |
472 } | |
473 if ( !b.isEmpty() ) | |
474 sl.push_back(b); | |
475 | |
476 return sl; | |
477 } | |
478 | |
479 | |
480 | |
422 static QString numStr(int n) | 481 static QString numStr(int n) |
423 { | 482 { |
424 QString s; | 483 QString s; |
425 s.setNum( n ); | 484 s.setNum( n ); |
426 return s; | 485 return s; |
491 m_map[k] = v; | 550 m_map[k] = v; |
492 } | 551 } |
493 | 552 |
494 void KConfig::writeEntry(const QString& k, const QStringList& v, char separator ) | 553 void KConfig::writeEntry(const QString& k, const QStringList& v, char separator ) |
495 { | 554 { |
496 QString s; | 555 m_map[k] = safeStringJoin(v, separator); |
497 | |
498 QStringList::ConstIterator i = v.begin(); | |
499 for( i=v.begin(); i!= v.end(); ++i ) | |
500 { | |
501 s += *i; | |
502 | |
503 if ( !(*i).isEmpty() ) | |
504 s += separator; | |
505 } | |
506 | |
507 m_map[k] = s; | |
508 } | 556 } |
509 | 557 |
510 | 558 |
511 QFont KConfig::readFontEntry(const QString& k, QFont* defaultVal ) | 559 QFont KConfig::readFontEntry(const QString& k, QFont* defaultVal ) |
512 { | 560 { |
598 } | 646 } |
599 | 647 |
600 return sval; | 648 return sval; |
601 } | 649 } |
602 | 650 |
603 QStringList KConfig::readListEntry(const QString& k, char /*separator*/ ) | 651 QStringList KConfig::readListEntry(const QString& k, char separator ) |
604 { | 652 { |
605 QStringList strList; | 653 QStringList strList; |
606 | 654 |
607 std::map<QString,QString>::iterator i = m_map.find( k ); | 655 std::map<QString,QString>::iterator i = m_map.find( k ); |
608 if ( i!=m_map.end() ) | 656 if ( i!=m_map.end() ) |
609 { | 657 { |
610 QString s = i->second; | 658 strList = safeStringSplit( i->second, separator ); |
611 int idx=0; | |
612 for(;;) | |
613 { | |
614 QString sec = subSection( s, idx, '|' ); //s.section('|',idx,idx); | |
615 if ( sec.isEmpty() ) | |
616 break; | |
617 else | |
618 strList.append(sec); | |
619 ++idx; | |
620 } | |
621 } | 659 } |
622 return strList; | 660 return strList; |
623 } | 661 } |
624 | 662 |
625 | 663 |
1040 return s_vArg.size(); | 1078 return s_vArg.size(); |
1041 } | 1079 } |
1042 | 1080 |
1043 QString KCmdLineArgs::arg(int idx) | 1081 QString KCmdLineArgs::arg(int idx) |
1044 { | 1082 { |
1045 return QString(s_vArg[idx]); | 1083 return QString::fromLocal8Bit( s_vArg[idx] ); |
1046 } | 1084 } |
1047 | 1085 |
1048 void KCmdLineArgs::clear() | 1086 void KCmdLineArgs::clear() |
1049 { | 1087 { |
1050 } | 1088 } |
1153 break; | 1191 break; |
1154 } | 1192 } |
1155 } | 1193 } |
1156 if (j==nofOptions) | 1194 if (j==nofOptions) |
1157 { | 1195 { |
1158 using std::cerr; | 1196 QString s; |
1159 using std::endl; | 1197 s = QString("Unknown option: ") + s_argv[i] + "\n"; |
1160 cerr << "Unknown option: " << s_argv[i] << endl<<endl; | 1198 |
1161 | 1199 s += "KDiff3-Usage when starting via commandline: \n"; |
1162 cerr << "Usage when starting via commandline: " << endl; | 1200 s += "- Comparing 2 files:\t\tkdiff3 file1 file2\n"; |
1163 cerr << "- Comparing 2 files: kdiff3 file1 file2 " << endl; | 1201 s += "- Merging 2 files: \t\tkdiff3 file1 file2 -o outputfile\n"; |
1164 cerr << "- Merging 2 files: kdiff3 file1 file2 -o outputfile " << endl; | 1202 s += "- Comparing 3 files:\t\tkdiff3 file1 file2 file3\n"; |
1165 cerr << "- Comparing 3 files: kdiff3 file1 file2 file3 " << endl; | 1203 s += "- Merging 3 files: \t\tkdiff3 file1 file2 file3 -o outputfile\n"; |
1166 cerr << "- Merging 3 files: kdiff3 file1 file2 file3 -o outputfile " << endl; | 1204 s += " Note that file1 will be treated as base of file2 and file3.\n"; |
1167 cerr << " Note that file1 will be treated as base of file2 and file3." << endl; | 1205 s += "\n"; |
1168 cerr << endl; | 1206 s += "If you start without arguments, then a dialog will appear\n"; |
1169 cerr << "If you start without arguments, then a dialog will appear" << endl; | 1207 s += "where you can select your files via a filebrowser.\n"; |
1170 cerr << "where you can select your files via a filebrowser." << endl; | 1208 s += "\n"; |
1171 cerr << endl; | 1209 s += "For more documentation, see the help-menu or the subdirectory doc.\n"; |
1172 cerr << "For more documentation, see the help-menu or the subdirectory doc. " << endl; | 1210 #ifdef _WIN32 |
1211 // A windows program has no console | |
1212 KMessageBox::information(0, s,i18n("KDiff3-Usage")); | |
1213 #else | |
1214 std::cerr << s.latin1() << std::endl; | |
1215 #endif | |
1216 | |
1173 ::exit(-1); | 1217 ::exit(-1); |
1174 } | 1218 } |
1175 } | 1219 } |
1176 else | 1220 else |
1177 s_vArg.push_back( s_argv[i] ); | 1221 s_vArg.push_back( s_argv[i] ); |
1248 return 0; | 1292 return 0; |
1249 } | 1293 } |
1250 | 1294 |
1251 | 1295 |
1252 | 1296 |
1297 | |
1253 #include "kreplacements.moc" | 1298 #include "kreplacements.moc" |