20 #include "kstringhandler.h"
21 #include "tdeglobal.h"
23 static void parsePythonRange(
const TQCString &range, uint &start, uint &end )
25 const int colon = range.find(
':' );
27 start = range.toUInt();
29 }
else if ( colon ==
int( range.length() - 1 ) ) {
30 start = range.left( colon ).toUInt();
31 }
else if ( colon == 0 ) {
32 end = range.mid( 1 ).toUInt();
34 start = range.left( colon ).toInt();
35 end = range.mid( colon + 1 ).toInt();
41 return text.section(
' ', pos, pos );
51 TQStringList list = TQStringList::split(
" ", text ,
true );
58 uint pos = 0, cnt = list.count();
59 parsePythonRange( range, pos, cnt );
64 int wordsToExtract = cnt-pos+1;
65 TQStringList::Iterator it = list.at( pos);
67 while ( (it != list.end()) && (wordsToExtract-- > 0))
74 return tmp.stripWhiteSpace();
89 TQStringList list = TQStringList::split(
" ", text,
true );
91 if ( pos >= list.count() )
94 list.insert( list.at(pos) ,
word );
97 return list.join(
" " );
102 if ( text.isEmpty() )
105 if (
word.isEmpty() )
109 TQStringList list = TQStringList::split(
" ", text,
true );
111 if ( pos >= list.count() )
115 list.insert( list.remove( list.at(pos) ) ,
word );
119 return list.join(
" " );
129 TQStringList list = TQStringList::split(
" ", text ,
true );
133 if ( text.isEmpty() )
136 uint pos = 0, cnt = list.count();
137 parsePythonRange( range, pos, cnt );
142 int wordsToDelete = cnt-pos+1;
143 TQStringList::Iterator it = list.at( pos);
145 while ( (it != list.end()) && (wordsToDelete-- > 0))
146 it = list.remove( it );
148 return list.join(
" " );
155 if ( text.isEmpty() )
159 TQStringList list = TQStringList::split(
" ", text,
true );
161 if ( pos < list.count() )
162 list.remove( list.at( pos ) );
165 return list.join(
" " );
172 if ( text.isEmpty() )
175 if (
word.isEmpty() )
179 TQStringList list = TQStringList::split(
" ", text,
true );
181 TQStringList::Iterator it = list.find(
word);
183 if (it != list.end())
187 return list.join(
" " );
195 if ( text.isEmpty() ) {
199 const TQString strippedText = text.stripWhiteSpace();
200 const TQStringList words =
capwords( TQStringList::split(
' ', strippedText ) );
202 TQString result = text;
203 result.replace( strippedText, words.join(
" " ) );
209 TQStringList tmp = list;
210 for ( TQStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it ) {
211 *it = ( *it )[ 0 ].upper() + ( *it ).mid( 1 );
223 if ( text.isEmpty() )
227 list = TQStringList::split(
" ", text,
true );
230 return list.join(
" " );
237 if ( list.count() == 0 )
240 for ( TQStringList::ConstIterator it= list.begin();
253 return text.stripWhiteSpace().leftJustify( width );
258 return text.stripWhiteSpace().rightJustify( width );
263 const TQString s = text.stripWhiteSpace();
264 const unsigned int length = s.length();
265 if ( width <= length ) {
270 result.fill(
' ', ( width - length ) / 2 );
273 return result.leftJustify( width );
278 if (str.length() > maxlen) {
280 return TQString(
"..." + str.right(part));
287 if (str.length() > maxlen && maxlen > 3) {
288 int part = (maxlen-3)/2;
289 return TQString(str.left(part) +
"..." + str.right(part));
296 if (str.length() > maxlen) {
298 return TQString(str.left(part) +
"...");
305 return lPixelSqueeze(name, fontMetrics, fontMetrics.maxWidth() * maxlen);
310 uint nameWidth = fontMetrics.width(name);
312 if (maxPixels < nameWidth)
315 const uint em = fontMetrics.maxWidth();
316 maxPixels -= fontMetrics.width(
"...");
318 while (maxPixels < nameWidth && !tmp.isEmpty())
320 int delta = (nameWidth - maxPixels) / em;
321 delta = kClamp(delta, 1, delta);
323 tmp.remove(0, delta);
324 nameWidth = fontMetrics.width(tmp);
327 return (
"..." + tmp);
335 return cPixelSqueeze(name, fontMetrics, fontMetrics.maxWidth() * maxlen);
340 if ( s.isEmpty() || uint( fm.width( s ) ) <= width ) {
344 const unsigned int length = s.length();
349 const int maxWidth = width - fm.width(
'.' ) * 3;
350 if ( maxWidth <= 0 ) {
354 unsigned int leftIdx = 0, rightIdx = length;
355 unsigned int leftWidth = fm.charWidth( s, leftIdx++ );
356 unsigned int rightWidth = fm.charWidth( s, --rightIdx );
357 while ( leftWidth + rightWidth < uint( maxWidth ) ) {
358 while ( leftWidth <= rightWidth && leftWidth + rightWidth < uint( maxWidth ) ) {
359 leftWidth += fm.charWidth( s, leftIdx++ );
361 while ( rightWidth <= leftWidth && leftWidth + rightWidth < uint( maxWidth ) ) {
362 rightWidth += fm.charWidth( s, --rightIdx );
366 if ( leftWidth > rightWidth ) {
372 rightIdx = length - rightIdx;
373 if ( leftIdx == 0 && rightIdx == 1 || leftIdx == 1 && rightIdx == 0 ) {
377 return s.left( leftIdx ) +
"..." + s.right( rightIdx );
382 return rPixelSqueeze(name, fontMetrics, fontMetrics.maxWidth() * maxlen);
387 uint nameWidth = fontMetrics.width(name);
389 if (maxPixels < nameWidth)
392 const uint em = fontMetrics.maxWidth();
393 maxPixels -= fontMetrics.width(
"...");
395 while (maxPixels < nameWidth && !tmp.isEmpty())
397 int length = tmp.length();
398 int delta = em ? (nameWidth - maxPixels) / em : length;
399 delta = kClamp(delta, 1, length) ;
401 tmp.remove(length - delta, delta);
402 nameWidth = fontMetrics.width(tmp);
405 return (tmp +
"...");
415 int len = filename.length();
416 int pattern_len = pattern.length();
422 if ( pattern[ pattern_len - 1 ] == (TQChar)
'*' && len + 1 >= pattern_len ) {
423 if ( pattern[ 0 ] == (TQChar)
'*' )
425 return filename.find(pattern.mid(1, pattern_len - 2)) != -1;
428 const TQChar *c1 = pattern.unicode();
429 const TQChar *c2 = filename.unicode();
431 while ( cnt < pattern_len && *c1++ == *c2++ )
433 return cnt == pattern_len;
437 if ( pattern[ 0 ] == (TQChar)
'*' && len + 1 >= pattern_len )
439 const TQChar *c1 = pattern.unicode() + pattern_len - 1;
440 const TQChar *c2 = filename.unicode() + len - 1;
442 while ( cnt < pattern_len && *c1-- == *c2-- )
444 return cnt == pattern_len;
448 return ( filename == pattern );
454 bool ignoreMax = 0 == max;
460 int tokenStart = s.find(sep, searchStart);
462 while (-1 != tokenStart && (ignoreMax || l.count() < max - 1))
464 if (!s.mid(searchStart, tokenStart - searchStart).isEmpty())
465 l << s.mid(searchStart, tokenStart - searchStart);
467 searchStart = tokenStart + sep.length();
468 tokenStart = s.find(sep, searchStart);
471 if (!s.mid(searchStart, s.length() - searchStart).isEmpty())
472 l << s.mid(searchStart, s.length() - searchStart);
480 bool ignoreMax = 0 == max;
486 int tokenStart = s.find(sep, searchStart);
488 while (-1 != tokenStart && (ignoreMax || l.count() < max - 1))
490 if (!s.mid(searchStart, tokenStart - searchStart).isEmpty())
491 l << s.mid(searchStart, tokenStart - searchStart);
493 searchStart = tokenStart + 1;
494 tokenStart = s.find(sep, searchStart);
497 if (!s.mid(searchStart, s.length() - searchStart).isEmpty())
498 l << s.mid(searchStart, s.length() - searchStart);
506 bool ignoreMax = 0 == max;
511 int tokenStart = sep.search(s, searchStart);
512 int len = sep.matchedLength();
514 while (-1 != tokenStart && (ignoreMax || l.count() < max - 1))
516 if (!s.mid(searchStart, tokenStart - searchStart).isEmpty())
517 l << s.mid(searchStart, tokenStart - searchStart);
519 searchStart = tokenStart + len;
520 tokenStart = sep.search(s, searchStart);
521 len = sep.matchedLength();
524 if (!s.mid(searchStart, s.length() - searchStart).isEmpty())
525 l << s.mid(searchStart, s.length() - searchStart);
533 TQRegExp urlEx(
"(www\\.(?!\\.)|(fish|(f|ht)tp(|s))://)[\\d\\w\\./,:_~\\?=&;#@\\-\\+\\%\\$]+[\\d\\w/]");
535 TQString richText( text );
536 int urlPos = 0, urlLen;
537 while ((urlPos = urlEx.search(richText, urlPos)) >= 0)
539 urlLen = urlEx.matchedLength();
540 TQString href = richText.mid( urlPos, urlLen );
542 if((urlPos > 0) && richText[urlPos-1].isLetterOrNumber()){
547 TQString anchor =
"<a href=\"" + href +
"\">" + href +
"</a>";
548 richText.replace( urlPos, urlLen, anchor );
551 urlPos += anchor.length();
559 const TQChar *unicode = str.unicode();
560 for ( uint i = 0; i < str.length(); ++i )
561 result += ( unicode[ i ].unicode() < 0x21 ) ? unicode[ i ] :
562 TQChar( 0x1001F - unicode[ i ].unicode() );
581 static const unsigned char text_chars[256] = {
583 F, F, F, F, F, F, F, T, T, T, T, F, T, T, F, F,
585 F, F, F, F, F, F, F, F, F, F, F, T, F, F, F, F,
586 T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,
587 T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,
588 T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,
589 T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,
590 T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, T,
591 T, T, T, T, T, T, T, T, T, T, T, T, T, T, T, F,
593 X, X, X, X, X, T, X, X, X, X, X, X, X, X, X, X,
594 X, X, X, X, X, X, X, X, X, X, X, X, X, X, X, X,
595 I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I,
596 I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I,
597 I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I,
598 I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I,
599 I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I,
600 I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I
604 for (i = 0; (c = buf[i]); i++) {
605 if ((c & 0x80) == 0) {
611 if (text_chars[c] != T)
614 }
else if ((c & 0x40) == 0) {
619 if ((c & 0x20) == 0) {
621 }
else if ((c & 0x10) == 0) {
623 }
else if ((c & 0x08) == 0) {
625 }
else if ((c & 0x04) == 0) {
627 }
else if ((c & 0x02) == 0) {
632 for (n = 0; n < following; n++) {
637 if ((c & 0x80) == 0 || (c & 0x40))
655 return TQString::null;
661 TQString::fromUtf8( str ) :
662 TQString::fromLocal8Bit( str );
static TQString cEmSqueeze(const TQString &name, const TQFontMetrics &fontMetrics, uint maxlen=30)
Substitute characters in the middle of a string by "...".
static TQString rEmSqueeze(const TQString &name, const TQFontMetrics &fontMetrics, uint maxlen=30)
Substitute characters at the end of a string by "...".
static TQStringList perlSplit(const TQString &sep, const TQString &s, uint max=0)
Split a TQString into a TQStringList in a similar fashion to the static TQStringList function in Qt,...
static TQString center(const TQString &text, uint width)
Centers a string and returns a string at least 'width' characters wide.
static TQString insword(const TQString &text, const TQString &word, uint pos)
Inserts a word into the string, and returns a new string with the word included.
static TQString word(const TQString &text, uint pos) TDE_DEPRECATED
Returns the nth word in the string if found Returns a EMPTY (not null) string otherwise.
static TQString cPixelSqueeze(const TQString &name, const TQFontMetrics &fontMetrics, uint maxPixels)
Substitute characters in the middle of a string by "...".
static TQString from8Bit(const char *str)
Construct TQString from a c string, guessing whether it is UTF8- or Local8Bit-encoded.
static TQString tagURLs(const TQString &text)
This method auto-detects URLs in strings, and adds HTML markup to them so that richtext or HTML-enabl...
static TQString rsqueeze(const TQString &str, uint maxlen=40)
Substitute characters at the end of a string by "...".
static TQString remrange(const TQString &text, const char *range)
Removes a word or ranges of words from the string, and returns a new string.
static TQString lEmSqueeze(const TQString &name, const TQFontMetrics &fontMetrics, uint maxlen=30)
Substitute characters at the beginning of a string by "...".
static TQString csqueeze(const TQString &str, uint maxlen=40)
Substitute characters at the middle of a string by "...".
static bool isUtf8(const char *str)
Guess whether a string is UTF8 encoded.
static TQString reverse(const TQString &text)
Reverses the order of the words in a string "hello there" becomes "there hello" (string)
static TQString setword(const TQString &text, const TQString &word, uint pos)
Replaces a word in the string, and returns a new string with the word included.
static TQString obscure(const TQString &str)
Obscure string by using a simple symmetric encryption.
static TQString rPixelSqueeze(const TQString &name, const TQFontMetrics &fontMetrics, uint maxPixels)
Substitute characters at the end of a string by "...".
static TQString lPixelSqueeze(const TQString &name, const TQFontMetrics &fontMetrics, uint maxPixels)
Substitute characters at the beginning of a string by "...".
static TQString lsqueeze(const TQString &str, uint maxlen=40)
Substitute characters at the beginning of a string by "...".
static TQString rjust(const TQString &text, uint width) TDE_DEPRECATED
Right-justifies a string and returns a string at least 'width' characters wide.
static bool matchFileName(const TQString &filename, const TQString &pattern)
Match a filename.
static TQString remword(const TQString &text, uint pos)
Removes a word at the given index, and returns a new string.
static TQString capwords(const TQString &text)
Capitalizes each word in the string "hello there" becomes "Hello There" (string)
static TQString ljust(const TQString &text, uint width) TDE_DEPRECATED
Left-justifies a string and returns a string at least 'width' characters wide.
static const TQString & staticQString(const char *str)
Creates a static TQString.
const TDEShortcut & end()
Goto end of the document.