summaryrefslogtreecommitdiff
path: root/library/backend/stringutil.cpp
Unidiff
Diffstat (limited to 'library/backend/stringutil.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/backend/stringutil.cpp415
1 files changed, 0 insertions, 415 deletions
diff --git a/library/backend/stringutil.cpp b/library/backend/stringutil.cpp
deleted file mode 100644
index df58f54..0000000
--- a/library/backend/stringutil.cpp
+++ b/dev/null
@@ -1,415 +0,0 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free
8** Software Foundation and appearing in the file LICENSE.GPL included
9** in the packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
12** THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
13** PARTICULAR PURPOSE.
14**
15** See http://www.trolltech.com/gpl/ for GPL licensing information.
16**
17** Contact info@trolltech.com if any conditions of this licensing are
18** not clear to you.
19**
20**********************************************************************/
21
22#include "stringutil.h"
23#include <qregexp.h>
24#include <qstringlist.h>
25
26namespace Qtopia
27{
28
29
30
31/*
32 Very, very simple Latin-1 only collation guaranteed to displease anyone
33 who actually uses the non-ASCII characters.
34 */
35
36static const char collationHack[] = {
370x00, //C-@
380x01, //C-A
390x02, //C-B
400x03, //C-C
410x04, //C-D
420x05, //C-E
430x06, //C-F
440x07, //C-G
450x08, //C-H
460x09, //C-I
470x0a, //C-J
480x0b, //C-K
490x0c, //C-L
500x0d, //C-M
510x0e, //C-N
520x0f, //C-O
530x10, //C-P
540x11, //C-Q
550x12, //C-R
560x13, //C-S
570x14, //C-T
580x15, //C-U
590x16, //C-V
600x17, //C-W
610x18, //C-X
620x19, //C-Y
630x1a, //C-Z
640x1b, //C-[
650x1c, //C-\
660x1d, //C-]
670x1e, //C-^
680x1f, //C-_
69' ', //
70'!', //!
71'"', //"
72'#', //#
73'$', //$
74'%', //%
75'&', //&
76'\'', //'
77'(', //(
78')', //)
79'*', //*
80'+', //+
81',', //,
82'-', //-
83'.', //.
84'/', ///
850x80, //0
860x81, //1
870x82, //2
880x83, //3
890x84, //4
900x85, //5
910x86, //6
920x87, //7
930x88, //8
940x89, //9
95':', //:
96';', //;
97'<', //<
98'=', //=
99'>', //>
100'?', //?
101'@', //@
102'A', //A
103'B', //B
104'C', //C
105'D', //D
106'E', //E
107'F', //F
108'G', //G
109'H', //H
110'I', //I
111'J', //J
112'K', //K
113'L', //L
114'M', //M
115'N', //N
116'O', //O
117'P', //P
118'Q', //Q
119'R', //R
120'S', //S
121'T', //T
122'U', //U
123'V', //V
124'W', //W
125'X', //X
126'Y', //Y
127'Z', //Z
128'[', //[
129'\\', //\
130']', //]
131'^', //^
132'_', //_
133'`', //`
134'A', //a
135'B', //b
136'C', //c
137'D', //d
138'E', //e
139'F', //f
140'G', //g
141'H', //h
142'I', //i
143'J', //j
144'K', //k
145'L', //l
146'M', //m
147'N', //n
148'O', //o
149'P', //p
150'Q', //q
151'R', //r
152'S', //s
153'T', //t
154'U', //u
155'V', //v
156'W', //w
157'X', //x
158'Y', //y
159'Z', //z
160'{', //{
161'|', //|
162'}', //}
163'~', //~
164'', //
1650x80, //C-M-@
1660x81, //C-M-A
1670x82, //C-M-B
1680x83, //C-M-C
1690x84, //C-M-D
1700x85, //C-M-E
1710x86, //C-M-F
1720x87, //C-M-G
1730x88, //C-M-H
1740x89, //C-M-I
1750x8a, //C-M-J
1760x8b, //C-M-K
1770x8c, //C-M-L
1780x8d, //C-M-M
1790x8e, //C-M-N
1800x8f, //C-M-O
1810x90, //C-M-P
1820x91, //C-M-Q
1830x92, //C-M-R
1840x93, //C-M-S
1850x94, //C-M-T
1860x95, //C-M-U
1870x96, //C-M-V
1880x97, //C-M-W
1890x98, //C-M-X
1900x99, //C-M-Y
1910x9a, //C-M-Z
1920x9b, //C-M-[
1930x9c, //C-M-\
1940x9d, //C-M-]
1950x9e, //C-M-^
1960x9f, //C-M-_
197' ', // 
198'¡', //¡
199'¢', //¢
200'£', //£
201'¤', //¤
202'¥', //¥
203'¦', //¦
204'§', //§
205'¨', //¨
206'©', //©
207'A', //ª
208'«', //«
209'¬', //¬
210'­', //­
211'®', //®
212'¯', //¯
213'O', //°
214'±', //±
215'²', //²
216'³', //³
217'´', //´
218'µ', //µ
219'P', //¶
220'·', //·
221'¸', //¸
222'¹', //¹
223'O', //º
224'»', //»
225'¼', //¼
226'½', //½
227'¾', //¾
228'¿', //¿
229'A', //À
230'A', //Á
231'A', //Â
232'A', //Ã
233'A', //Ä
234'A', //Å
235'A', //Æ
236'C', //Ç
237'E', //È
238'E', //É
239'E', //Ê
240'E', //Ë
241'I', //Ì
242'I', //Í
243'I', //Î
244'I', //Ï
245'D', //Ð
246'N', //Ñ
247'O', //Ò
248'O', //Ó
249'O', //Ô
250'O', //Õ
251'O', //Ö
252'×', //×
253'O', //Ø
254'U', //Ù
255'U', //Ú
256'U', //Û
257'U', //Ü
258'Y', //Ý
259'T', //Þ
260'S', //ß
261'A', //à
262'A', //á
263'A', //â
264'A', //ã
265'A', //ä
266'A', //å
267'A', //æ
268'C', //ç
269'E', //è
270'E', //é
271'E', //ê
272'E', //ë
273'I', //ì
274'I', //í
275'I', //î
276'I', //ï
277'D', //ð
278'N', //ñ
279'O', //ò
280'O', //ó
281'O', //ô
282'O', //õ
283'O', //ö
284'÷', //÷
285'O', //ø
286'U', //ù
287'U', //ú
288'U', //û
289'U', //ü
290'Y', //ý
291'T', //þ
292'Y', //ÿ
293};
294
295
296
297
298
299static void hackString ( QString &s )
300{
301 int len = s.length();
302 const QChar* uc = s.unicode();
303 for ( int i = 0; i < len; i++ ) {
304 if ( !uc++->row() )
305 s[i] = collationHack[s[i].cell()];
306 }
307}
308
309QString buildSortKey( const QString & s )
310{
311 QString res = s;
312 hackString( res );
313 return res;
314}
315
316QString buildSortKey( const QString & s1, const QString & s2 )
317{
318 QString res = s1 + QChar( '\0' ) + s2;
319 hackString( res );
320 return res;
321}
322
323QString buildSortKey( const QString & s1, const QString & s2,
324 const QString & s3 )
325{
326 QString res = s1 + QChar( '\0' ) + s2 + QChar( '\0' ) + s3;
327 hackString( res );
328 return res;
329}
330
331static inline QChar coll( QChar u )
332{
333 return u.row() ? u : QChar(collationHack[ u.cell() ]);
334}
335
336
337int compare( const QString & s1, const QString & s2 )
338{
339 const QChar* u1 = s1.unicode();
340 const QChar* u2 = s2.unicode();
341
342 if ( u1 == u2 )
343 return 0;
344 if ( u1 == 0 )
345 return 1;
346 if ( u2 == 0 )
347 return -1;
348 int l=QMIN(s1.length(),s2.length());
349 while ( l-- && coll(*u1) == coll(*u2) )
350 u1++,u2++;
351 if ( l==-1 )
352 return ( s1.length()-s2.length() );
353 return u1->unicode() - u2->unicode();
354}
355
356QString simplifyMultiLineSpace( const QString &multiLine )
357{
358 QString result;
359 QStringList lines = QStringList::split("\n", multiLine);
360 for ( QStringList::Iterator it = lines.begin(); it != lines.end(); ++it ) {
361 if ( it != lines.begin() )
362 result += "\n";
363 result += (*it).simplifyWhiteSpace();
364 }
365 return result;
366}
367
368QString escapeString( const QString& plain )
369{
370 QString tmp(plain);
371 int pos = tmp.length();
372 const QChar *uc = plain.unicode();
373 while ( pos-- ) {
374 unsigned char ch = uc[pos].latin1();
375 if ( ch == '&' )
376 tmp.replace( pos, 1, "&amp;" );
377 else if ( ch == '<' )
378 tmp.replace( pos, 1, "&lt;" );
379 else if ( ch == '>' )
380 tmp.replace( pos, 1, "&gt;" );
381 else if ( ch == '\"' )
382 tmp.replace( pos, 1, "&quot;" );
383 }
384 return tmp;
385}
386
387QString plainString( const char* escaped, unsigned int length )
388{
389 return plainString( QString::fromUtf8( escaped, length ) );
390}
391
392QString plainString( const QCString& string )
393{
394 // We first have to pass it through a ::fromUtf8()
395 return plainString( string.data(), string.length() );
396}
397
398QString plainString( const QString& string )
399{
400 QString tmp( string );
401 int pos = -1;
402 while ( (pos = tmp.find( "&", pos +1 ) ) != -1 ) {
403 if ( tmp.find( "&amp;", pos ) == pos )
404 tmp.replace( pos, 5, "&" );
405 else if ( tmp.find( "&lt;", pos ) == pos )
406 tmp.replace( pos, 4, "<" );
407 else if( tmp.find( "&gt;", pos ) == pos )
408 tmp.replace( pos, 4, ">" );
409 else if ( tmp.find( "&quot;", pos ) == pos )
410 tmp.replace( pos, 6, "\"" );
411 }
412 return tmp;
413}
414
415} // namespace QPC