SIP4 python bindings for TQt
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.5KB

  1. /**********************************************************************
  2. ** Copyright (C) 2000 Trolltech AS. All rights reserved.
  3. **
  4. ** proparser.cpp
  5. **
  6. ** This file is part of TQt Linguist.
  7. **
  8. ** See the file LICENSE included in the distribution for the usage
  9. ** and distribution terms.
  10. **
  11. ** The file is provided AS IS with NO WARRANTY OF ANY KIND,
  12. ** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
  13. ** A PARTICULAR PURPOSE.
  14. **
  15. **********************************************************************/
  16. #include <qregexp.h>
  17. #include <qstringlist.h>
  18. #include "proparser.h"
  19. TQMap<TQString, TQString> proFileTagMap( const TQString& text )
  20. {
  21. TQString t = text;
  22. /*
  23. Strip comments, merge lines ending with backslash, add
  24. spaces around '=' and '+=', replace '\n' with ';', and
  25. simplify white spaces.
  26. */
  27. t.replace( TQRegExp(TQString("#[^\n]$")), TQString(" ") );
  28. t.replace( TQRegExp(TQString("\\\\\\s*\n")), TQString(" ") );
  29. t.replace( TQRegExp(TQString("=")), TQString(" = ") );
  30. t.replace( TQRegExp(TQString("\\+ =")), TQString(" += ") );
  31. t.replace( TQRegExp(TQString("\n")), TQString(";") );
  32. t = t.simplifyWhiteSpace();
  33. TQMap<TQString, TQString> tagMap;
  34. TQStringList lines = TQStringList::split( TQChar(';'), t );
  35. TQStringList::Iterator line;
  36. for ( line = lines.begin(); line != lines.end(); ++line ) {
  37. TQStringList toks = TQStringList::split( TQChar(' '), *line );
  38. if ( toks.count() >= 3 &&
  39. (toks[1] == TQString("=") || toks[1] == TQString("+=")) ) {
  40. TQString tag = toks.first();
  41. int k = tag.findRev( TQChar(':') ); // as in 'unix:'
  42. if ( k != -1 )
  43. tag = tag.mid( k + 1 );
  44. toks.remove( toks.begin() );
  45. TQString action = toks.first();
  46. toks.remove( toks.begin() );
  47. if ( tagMap.contains(tag) ) {
  48. if ( action == TQString("=") )
  49. tagMap.replace( tag, toks.join(TQChar(' ')) );
  50. else
  51. tagMap[tag] += TQChar( ' ' ) + toks.join( TQChar(' ') );
  52. } else {
  53. tagMap[tag] = toks.join( TQChar(' ') );
  54. }
  55. }
  56. }
  57. TQRegExp var( "\\$\\$[a-zA-Z0-9_]+" );
  58. TQMap<TQString, TQString>::Iterator it;
  59. for ( it = tagMap.begin(); it != tagMap.end(); ++it ) {
  60. int i = 0;
  61. while ( (i = var.search(it.data(), i)) != -1 ) {
  62. int len = var.matchedLength();
  63. (*it).replace( i, len, tagMap[(*it).mid(i + 2, len - 2)] );
  64. }
  65. }
  66. return tagMap;
  67. }