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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
|
/****************************************************************************
**
** Implementation of the TQChar class and related Unicode functions
**
** Created : 920722
**
** Copyright (C) 2015 Timothy Pearson. All rights reserved.
** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
**
** This file is part of the tools module of the TQt GUI Toolkit.
**
** This file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free
** Software Foundation and appearing in the files LICENSE.GPL2
** and LICENSE.GPL3 included in the packaging of this file.
** Alternatively you may (at your option) use any later version
** of the GNU General Public License if such license has been
** publicly approved by Trolltech ASA (or its successors, if any)
** and the KDE Free TQt Foundation.
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/.
** If you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at [email protected].
**
** This file may be used under the terms of the Q Public License as
** defined by Trolltech ASA and appearing in the file LICENSE.TQPL
** included in the packaging of this file. Licensees holding valid TQt
** Commercial licenses may use this file in accordance with the TQt
** Commercial License Agreement provided with the Software.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted
** herein.
**
**********************************************************************/
#include "tqchar.h"
#include "tqunicodetables_p.h"
/*!
\class TQChar tqchar.h
\reentrant
\brief The TQChar class provides a lightweight Unicode character.
\ingroup text
Unicode characters are (so far) 16-bit entities without any markup
or structure. This class represents such an entity. It is
lightweight, so it can be used everywhere. Most compilers treat it
like a "short int". (In a few years it may be necessary to make
TQChar 32-bit when more than 65536 Unicode code points have been
defined and come into use.)
TQChar provides a full complement of testing/classification
functions, converting to and from other formats, converting from
composed to decomposed Unicode, and trying to compare and
case-convert if you ask it to.
The classification functions include functions like those in
ctype.h, but operating on the full range of Unicode characters.
They all return TRUE if the character is a certain type of
character; otherwise they return FALSE. These classification
functions are isNull() (returns TRUE if the character is U+0000),
isPrint() (TRUE if the character is any sort of printable
character, including whitespace), isPunct() (any sort of
punctation), isMark() (Unicode Mark), isLetter (a letter),
isNumber() (any sort of numeric character), isLetterOrNumber(),
and isDigit() (decimal digits). All of these are wrappers around
category() which return the Unicode-defined category of each
character.
TQChar further provides direction(), which indicates the "natural"
writing direction of this character. The joining() function
indicates how the character joins with its neighbors (needed
mostly for Arabic) and finally mirrored(), which indicates whether
the character needs to be mirrored when it is printed in its
"unnatural" writing direction.
Composed Unicode characters (like å) can be converted to
decomposed Unicode ("a" followed by "ring above") by using
decomposition().
In Unicode, comparison is not necessarily possible and case
conversion is very difficult at best. Unicode, covering the
"entire" world, also includes most of the world's case and sorting
problems. TQt tries, but not very hard: operator==() and friends
will do comparison based purely on the numeric Unicode value (code
point) of the characters, and upper() and lower() will do case
changes when the character has a well-defined upper/lower-case
equivalent. There is no provision for locale-dependent case
folding rules or comparison; these functions are meant to be fast
so they can be used unambiguously in data structures. (See
TQString::localeAwareCompare() though.)
The conversion functions include unicode() (to a scalar), latin1()
(to scalar, but converts all non-Latin-1 characters to 0), row()
(gives the Unicode row), cell() (gives the Unicode cell),
digitValue() (gives the integer value of any of the numerous digit
characters), and a host of constructors.
More information can be found in the document \link unicode.html
About Unicode. \endlink
\sa TQString TQCharRef
*/
/*!
\enum TQChar::Category
This enum maps the Unicode character categories.
The following characters are normative in Unicode:
\value Mark_NonSpacing Unicode class name Mn
\value Mark_SpacingCombining Unicode class name Mc
\value Mark_Enclosing Unicode class name Me
\value Number_DecimalDigit Unicode class name Nd
\value Number_Letter Unicode class name Nl
\value Number_Other Unicode class name No
\value Separator_Space Unicode class name Zs
\value Separator_Line Unicode class name Zl
\value Separator_Paragraph Unicode class name Zp
\value Other_Control Unicode class name Cc
\value Other_Format Unicode class name Cf
\value Other_Surrogate Unicode class name Cs
\value Other_PrivateUse Unicode class name Co
\value Other_NotAssigned Unicode class name Cn
The following categories are informative in Unicode:
\value Letter_Uppercase Unicode class name Lu
\value Letter_Lowercase Unicode class name Ll
\value Letter_Titlecase Unicode class name Lt
\value Letter_Modifier Unicode class name Lm
\value Letter_Other Unicode class name Lo
\value Punctuation_Connector Unicode class name Pc
\value Punctuation_Dash Unicode class name Pd
\value Punctuation_Open Unicode class name Ps
\value Punctuation_Close Unicode class name Pe
\value Punctuation_InitialQuote Unicode class name Pi
\value Punctuation_FinalQuote Unicode class name Pf
\value Punctuation_Other Unicode class name Po
\value Symbol_Math Unicode class name Sm
\value Symbol_Currency Unicode class name Sc
\value Symbol_Modifier Unicode class name Sk
\value Symbol_Other Unicode class name So
There are two categories that are specific to TQt:
\value NoCategory used when TQt is dazed and confused and cannot
make sense of anything.
\value Punctuation_Dask old typo alias for Punctuation_Dash
*/
/*!
\enum TQChar::Direction
This enum type defines the Unicode direction attributes. See \link
http://www.unicode.org/ the Unicode Standard\endlink for a
description of the values.
In order to conform to C/C++ naming conventions "Dir" is prepended
to the codes used in the Unicode Standard.
*/
/*!
\enum TQChar::Decomposition
This enum type defines the Unicode decomposition attributes. See
\link http://www.unicode.org/ the Unicode Standard\endlink for a
description of the values.
*/
/*!
\enum TQChar::Joining
This enum type defines the Unicode joining attributes. See \link
http://www.unicode.org/ the Unicode Standard\endlink for a
description of the values.
*/
/*!
\enum TQChar::CombiningClass
This enum type defines names for some of the Unicode combining
classes. See \link http://www.unicode.org/ the Unicode
Standard\endlink for a description of the values.
*/
/*!
\fn void TQChar::setCell( uchar cell )
\internal
*/
/*!
\fn void TQChar::setRow( uchar row )
\internal
*/
/*!
\fn TQChar::TQChar()
Constructs a null TQChar (one that isNull()).
*/
/*!
\fn TQChar::TQChar( char c )
Constructs a TQChar corresponding to ASCII/Latin-1 character \a c.
*/
/*!
\fn TQChar::TQChar( uchar c )
Constructs a TQChar corresponding to ASCII/Latin-1 character \a c.
*/
/*!
\fn TQChar::TQChar( uchar c, uchar r )
Constructs a TQChar for Unicode cell \a c in row \a r.
*/
/*!
\fn TQChar::TQChar( const TQChar& c )
Constructs a copy of \a c. This is a deep copy, if such a
lightweight object can be said to have deep copies.
*/
/*!
\fn TQChar::TQChar( ushort rc )
Constructs a TQChar for the character with Unicode code point \a rc.
*/
/*!
\fn TQChar::TQChar( short rc )
Constructs a TQChar for the character with Unicode code point \a rc.
*/
/*!
\fn TQChar::TQChar( uint rc )
Constructs a TQChar for the character with Unicode code point \a rc.
*/
/*!
\fn TQChar::TQChar( int rc )
Constructs a TQChar for the character with Unicode code point \a rc.
*/
/*!
\fn bool TQChar::networkOrdered ()
\obsolete
Returns TRUE if this character is in network byte order (MSB
first); otherwise returns FALSE. This is platform dependent.
*/
/*!
\fn bool TQChar::isNull() const
Returns TRUE if the character is the Unicode character 0x0000
(ASCII NUL); otherwise returns FALSE.
*/
/*!
\fn uchar TQChar::cell () const
Returns the cell (least significant byte) of the Unicode
character.
*/
/*!
\fn uchar TQChar::row () const
Returns the row (most significant byte) of the Unicode character.
*/
/*!
\fn TQChar::operator char() const
Returns the Latin-1 character equivalent to the TQChar, or 0. This
is mainly useful for non-internationalized software.
\sa unicode()
*/
/*!
\fn ushort TQChar::unicode() const
Returns the numeric Unicode value equal to the TQChar. Normally,
you should use TQChar objects as they are equivalent, but for some
low-level tasks (e.g. indexing into an array of Unicode
information), this function is useful.
*/
/*!
\fn ushort & TQChar::unicode()
\overload
Returns a reference to the numeric Unicode value equal to the
TQChar.
*/
/*****************************************************************************
Documentation of TQChar related functions
*****************************************************************************/
/*!
\fn bool operator==( TQChar c1, TQChar c2 )
\relates TQChar
Returns TRUE if \a c1 and \a c2 are the same Unicode character;
otherwise returns FALSE.
*/
/*!
\fn bool operator==( char ch, TQChar c )
\overload
\relates TQChar
Returns TRUE if \a c is the ASCII/Latin-1 character \a ch;
otherwise returns FALSE.
*/
/*!
\fn bool operator==( TQChar c, char ch )
\overload
\relates TQChar
Returns TRUE if \a c is the ASCII/Latin-1 character \a ch;
otherwise returns FALSE.
*/
/*!
\fn int operator!=( TQChar c1, TQChar c2 )
\relates TQChar
Returns TRUE if \a c1 and \a c2 are not the same Unicode
character; otherwise returns FALSE.
*/
/*!
\fn int operator!=( char ch, TQChar c )
\overload
\relates TQChar
Returns TRUE if \a c is not the ASCII/Latin-1 character \a ch;
otherwise returns FALSE.
*/
/*!
\fn int operator!=( TQChar c, char ch )
\overload
\relates TQChar
Returns TRUE if \a c is not the ASCII/Latin-1 character \a ch;
otherwise returns FALSE.
*/
/*!
\fn int operator<=( TQChar c1, TQChar c2 )
\relates TQChar
Returns TRUE if the numeric Unicode value of \a c1 is less than
that of \a c2, or they are the same Unicode character; otherwise
returns FALSE.
*/
/*!
\fn int operator<=( TQChar c, char ch )
\overload
\relates TQChar
Returns TRUE if the numeric Unicode value of \a c is less than or
equal to that of the ASCII/Latin-1 character \a ch; otherwise
returns FALSE.
*/
/*!
\fn int operator<=( char ch, TQChar c )
\overload
\relates TQChar
Returns TRUE if the numeric Unicode value of the ASCII/Latin-1
character \a ch is less than or equal to that of \a c; otherwise
returns FALSE.
*/
/*!
\fn int operator>=( TQChar c1, TQChar c2 )
\relates TQChar
Returns TRUE if the numeric Unicode value of \a c1 is greater than
that of \a c2, or they are the same Unicode character; otherwise
returns FALSE.
*/
/*!
\fn int operator>=( TQChar c, char ch )
\overload
\relates TQChar
Returns TRUE if the numeric Unicode value of \a c is greater than
or equal to that of the ASCII/Latin-1 character \a ch; otherwise
returns FALSE.
*/
/*!
\fn int operator>=( char ch, TQChar c )
\overload
\relates TQChar
Returns TRUE if the numeric Unicode value of the ASCII/Latin-1
character \a ch is greater than or equal to that of \a c;
otherwise returns FALSE.
*/
/*!
\fn int operator<( TQChar c1, TQChar c2 )
\relates TQChar
Returns TRUE if the numeric Unicode value of \a c1 is less than
that of \a c2; otherwise returns FALSE.
*/
/*!
\fn int operator<( TQChar c, char ch )
\overload
\relates TQChar
Returns TRUE if the numeric Unicode value of \a c is less than that
of the ASCII/Latin-1 character \a ch; otherwise returns FALSE.
*/
/*!
\fn int operator<( char ch, TQChar c )
\overload
\relates TQChar
Returns TRUE if the numeric Unicode value of the ASCII/Latin-1
character \a ch is less than that of \a c; otherwise returns
FALSE.
*/
/*!
\fn int operator>( TQChar c1, TQChar c2 )
\relates TQChar
Returns TRUE if the numeric Unicode value of \a c1 is greater than
that of \a c2; otherwise returns FALSE.
*/
/*!
\fn int operator>( TQChar c, char ch )
\overload
\relates TQChar
Returns TRUE if the numeric Unicode value of \a c is greater than
that of the ASCII/Latin-1 character \a ch; otherwise returns FALSE.
*/
/*!
\fn int operator>( char ch, TQChar c )
\overload
\relates TQChar
Returns TRUE if the numeric Unicode value of the ASCII/Latin-1
character \a ch is greater than that of \a c; otherwise returns
FALSE.
*/
const TQChar TQChar::null;
const TQChar TQChar::replacement((ushort)0xfffd);
const TQChar TQChar::byteOrderMark((ushort)0xfeff);
const TQChar TQChar::byteOrderSwapped((ushort)0xfffe);
const TQChar TQChar::nbsp((ushort)0x00a0);
/*!
Returns TRUE if the character is a printable character; otherwise
returns FALSE. This is any character not of category Cc or Cn.
Note that this gives no indication of whether the character is
available in a particular \link TQFont font\endlink.
*/
bool TQChar::isPrint() const
{
Category c = ::category( *this );
return !(c == Other_Control || c == Other_NotAssigned);
}
/*!
Returns TRUE if the character is a separator character
(Separator_* categories); otherwise returns FALSE.
*/
bool TQChar::isSpace() const
{
return ::isSpace( *this );
}
/*!
Returns TRUE if the character is a mark (Mark_* categories);
otherwise returns FALSE.
*/
bool TQChar::isMark() const
{
Category c = ::category( *this );
return c >= Mark_NonSpacing && c <= Mark_Enclosing;
}
/*!
Returns TRUE if the character is a punctuation mark (Punctuation_*
categories); otherwise returns FALSE.
*/
bool TQChar::isPunct() const
{
Category c = ::category( *this );
return (c >= Punctuation_Connector && c <= Punctuation_Other);
}
/*!
Returns TRUE if the character is a letter (Letter_* categories);
otherwise returns FALSE.
*/
bool TQChar::isLetter() const
{
Category c = ::category( *this );
return (c >= Letter_Uppercase && c <= Letter_Other);
}
/*!
Returns TRUE if the character is a number (of any sort - Number_*
categories); otherwise returns FALSE.
\sa isDigit()
*/
bool TQChar::isNumber() const
{
Category c = ::category( *this );
return c >= Number_DecimalDigit && c <= Number_Other;
}
/*!
Returns TRUE if the character is a letter or number (Letter_* or
Number_* categories); otherwise returns FALSE.
*/
bool TQChar::isLetterOrNumber() const
{
Category c = ::category( *this );
return (c >= Letter_Uppercase && c <= Letter_Other)
|| (c >= Number_DecimalDigit && c <= Number_Other);
}
/*!
Returns TRUE if the character is a decimal digit
(Number_DecimalDigit); otherwise returns FALSE.
*/
bool TQChar::isDigit() const
{
return (::category( *this ) == Number_DecimalDigit);
}
/*!
Returns TRUE if the character is a symbol (Symbol_* categories);
otherwise returns FALSE.
*/
bool TQChar::isSymbol() const
{
Category c = ::category( *this );
return c >= Symbol_Math && c <= Symbol_Other;
}
/*!
Returns the numeric value of the digit, or -1 if the character is
not a digit.
*/
int TQChar::digitValue() const
{
#ifndef TQT_NO_UNICODETABLES
int pos = TQUnicodeTables::decimal_info[row()];
if( !pos )
return -1;
return TQUnicodeTables::decimal_info[(pos<<8) + cell()];
#else
// ##### just latin1
if ( ucs < '0' || ucs > '9' )
return -1;
else
return ucs - '0';
#endif
}
/*!
Returns the character category.
\sa Category
*/
TQChar::Category TQChar::category() const
{
return ::category( *this );
}
/*!
Returns the character's direction.
\sa Direction
*/
TQChar::Direction TQChar::direction() const
{
return ::direction( *this );
}
/*!
\warning This function is not supported (it may change to use
Unicode character classes).
Returns information about the joining properties of the character
(needed for example, for Arabic).
*/
TQChar::Joining TQChar::joining() const
{
return ::joining( *this );
}
/*!
Returns TRUE if the character is a mirrored character (one that
should be reversed if the text direction is reversed); otherwise
returns FALSE.
*/
bool TQChar::mirrored() const
{
return ::mirrored( *this );
}
/*!
Returns the mirrored character if this character is a mirrored
character, otherwise returns the character itself.
*/
TQChar TQChar::mirroredChar() const
{
return ::mirroredChar( *this );
}
#ifndef TQT_NO_UNICODETABLES
// ### REMOVE ME 4.0
static TQString shared_decomp;
#endif
/*!
\nonreentrant
Decomposes a character into its parts. Returns TQString::null if no
decomposition exists.
*/
const TQString &TQChar::decomposition() const
{
#ifndef TQT_NO_UNICODETABLES
int pos = TQUnicodeTables::decomposition_info[row()];
if(!pos) return TQString::null;
pos = TQUnicodeTables::decomposition_info[(pos<<8)+cell()];
if(!pos) return TQString::null;
pos+=2;
TQString s;
TQ_UINT16 c;
while ( (c = TQUnicodeTables::decomposition_map[pos++]) != 0 )
s += TQChar( c );
// ### In 4.0, return s, and not shared_decomp. shared_decomp
// prevents this function from being reentrant.
shared_decomp = s;
return shared_decomp;
#else
return TQString::null;
#endif
}
/*!
Returns the tag defining the composition of the character. Returns
TQChar::Single if no decomposition exists.
*/
TQChar::Decomposition TQChar::decompositionTag() const
{
#ifndef TQT_NO_UNICODETABLES
int pos = TQUnicodeTables::decomposition_info[row()];
if(!pos) return TQChar::Single;
pos = TQUnicodeTables::decomposition_info[(pos<<8)+cell()];
if(!pos) return TQChar::Single;
return (TQChar::Decomposition) TQUnicodeTables::decomposition_map[pos];
#else
return Single; // ########### FIX eg. just latin1
#endif
}
/*!
Returns the combining class for the character as defined in the
Unicode standard. This is mainly useful as a positioning hint for
marks attached to a base character.
The TQt text rendering engine uses this information to correctly
position non spacing marks around a base character.
*/
unsigned char TQChar::combiningClass() const
{
return ::combiningClass( *this );
}
/*!
Returns the lowercase equivalent if the character is uppercase;
otherwise returns the character itself.
*/
TQChar TQChar::lower() const
{
return ::lower( *this );
}
/*!
Returns the uppercase equivalent if the character is lowercase;
otherwise returns the character itself.
*/
TQChar TQChar::upper() const
{
return ::upper( *this );
}
|