1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
//
// $Id$
//
// Implementation of QaPerlLanguage class
//
// Jan Borsodi <jb@ez.no>
// Created on: <05-Sep-2000 18:18:15 amos>
//
// Copyright (C) Jan Borsodi. All rights reserved.
#include "qaperllanguage.hpp"
#include <qstring.h>
/*! \file qaperllanguage.cpp
Implementation of QaPerlLanguage class
*/
/*!
\class QaPerlLanguage qaperllanguage.hpp
\brief
\author <a href="mailto:jb@ez.no">Jan Borsodi</a>
\date Enter current date here
*/
/*!
Default constructor
*/
QaPerlLanguage::QaPerlLanguage()
: QaRegExpLanguage()
{
}
/*!
Destroys the object
*/
QaPerlLanguage::~QaPerlLanguage()
{
}
/*!
Converts to Perl
*/
QString QaPerlLanguage::fromPlainText( const QString &s, bool code, MatchType type )
{
QString str;
unsigned int i = 0;
bool bracket = false;
bool negated = false;
// ( i = s.find( "\\", i ) ) != -1 )
for ( i = 0; i < s.length(); i++ )
{
QChar c2 = s.at( i );
if ( bracket )
{
if ( c2 == ']' )
{
bracket = false;
negated = false;
str += c2;
}
else if ( c2 == '^' )
{
negated = true;
str += c2;
}
// else if ( c2 == '"' && code )
// {
// str += "\\";
// str += c2;
// }
else if ( c2 == '\\' )
{
i++;
if ( i < s.length() )
{
QChar c = s.at( i );
if ( c == "t" )
str += "\\t";
else if ( c == "n" )
str += "\\n";
else if ( c == "r" )
str += "\\r";
else if ( c == "f" )
str += "\\f";
else if ( c == "d" )
str += "\\d";
else if ( c == "D" )
str += "\\D";
else if ( c == "w" )
str += "\\w";
else if ( c == "W" )
str += "\\W";
else if ( c == 'c' )
str += "\\c";
else if ( c == 'C' )
str += "\\C";
else if ( c == 'i' )
str += "\\i";
else if ( c == "s" )
str += "\\s";
else if ( c == "S" )
str += "\\S";
else if ( c == "]" )
str += "\\]";
else if ( c == "\\" )
str += "\\\\";
else
{
str += c2;
str += c;
}
}
else
str += c2;
}
else if ( c2 == "/" )
str += "\\/";
else
str += c2;
}
//\a<(class|public|private|protected|typename|signals|slots)>
else
{
if ( c2 == '[' )
{
bracket = true;
negated = false;
str += c2;
}
// else if ( c2 == '"' && code )
// {
// str += "\\";
// str += c2;
// }
else if ( c2 == '\\' )
{
i++;
if ( i < s.length() )
{
QChar c = s.at( i );
if ( c == 't' )
str += "\\t";
else if ( c == 'n' )
str += "\\n";
else if ( c == 'r' )
str += "\\r";
else if ( c == 'f' )
str += "\\f";
else if ( c == 'd' )
str += "[0-9]";
else if ( c == 'D' )
str += "[^0-9]";
else if ( c == 'w' )
str += "\\w";
else if ( c == 'W' )
str += "\\W";
else if ( c == 'c' )
str += "\\c";
else if ( c == 'C' )
str += "\\C";
else if ( c == 'i' )
str += "\\i";
else if ( c == 'I' )
str += "\\I";
else if ( c == 's' )
str += "\\s";
else if ( c == 'S' )
str += "\\S";
// else if ( c == "]" )
// str += "\\]";
else if ( c == '\\' )
str += "\\\\";
else
{
str += c2;
str += c;
}
}
else
str += c2;
}
else if ( c2 == "/" )
str += "\\/";
else
str += c2;
}
}
if ( code )
{
if ( type == QaRegExpLanguage::Multiple )
{
str = QString( "=~ /%1/g" ).arg( str );
}
else if ( type == QaRegExpLanguage::Split )
{
str = QString( "split( /%1/ )" ).arg( str );
}
else
{
str = QString( "=~ /%1/" ).arg( str );
}
}
return str;
}
|