📄 qstring.cpp
字号:
/****************************************************************************** $Id: qt/src/tools/qstring.cpp 2.2.3 edited 2000-12-11 $**** Implementation of the QString class and related Unicode functions**** Created : 920722**** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.**** This file is part of the tools module of the Qt GUI Toolkit.**** This file may be distributed under the terms of the Q Public License** as defined by Trolltech AS of Norway and appearing in the file** LICENSE.QPL included in the packaging of this file.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition** licenses may use this file in accordance with the Qt Commercial License** Agreement provided with the Software.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for** information about Qt Commercial License Agreements.** See http://www.trolltech.com/qpl/ for QPL licensing information.** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/// Don't define it while compiling this module, or USERS of Qt will// not be able to link.#ifdef QT_NO_CAST_ASCII#undef QT_NO_CAST_ASCII#endif#include "qstring.h"#include "qregexp.h"#include "qdatastream.h"#include "qtextcodec.h"#include "qstack.h"#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <ctype.h>#include <limits.h>/* ------------------------------------------------------------------------- * unicode information * these tables are generated from the unicode reference file * ftp://ftp.unicode.org/Public/3.0-Update/UnicodeData-3.0.0.html * * Lars Knoll <knoll@mpi-hd.mpg.de> * ------------------------------------------------------------------------- *//* Perl script to generate (run perl -x tools/qstring.cpp)#!perlsub numberize{ my(%r, $n, $id); for $id ( @_ ) { $id="" if $id eq "EMPTY"; $r{$id}=$n++; } return %r;}# Code to integer mappings...#%category_code = numberize(qw{ EMPTY Mn Mc Me Nd Nl No Zs Zl Zp Cc Cf Cs Co Cn Lu Ll Lt Lm Lo Pc Pd Ps Pe Pi Pf Po Sm Sc Sk So});%bidi_category_code = numberize(qw{ L R EN ES ET AN CS B S WS ON LRE LRO AL RLE RLO PDF NSM BN});%character_decomposition_tag = numberize(qw{ <single> <canonical> <font> <noBreak> <initial> <medial> <final> <isolated> <circle> <super> <sub> <vertical> <wide> <narrow> <small> <square> <compat> <fraction>});%mirrored_code = numberize(qw{N Y});%joining_code = numberize(qw{U D R C});# Read data into hashes...#open IN, "UnicodeData.txt";$position = 1;while (<IN>) { @fields = split /;/; $code = shift @fields; for $n (qw{ name category combining_class bidi_category character_decomposition decimal_digit_value digit_value numeric_value mirrored oldname comment uppercase lowercase titlecase}) { $id = shift @fields; $codes = "${n}_code"; if ( defined %$codes && defined $$codes{$id} ) { $id = $$codes{$id}; } ${$n}{$code}=$id; } $decomp = $character_decomposition{$code}; if ( length $decomp == 0 ) { $decomp = "<single>"; } if (substr($decomp, 0, 1) ne '<') { $decomp = "<canonical> " . $decomp; } @fields = split(" ", $decomp); $tag = shift @fields; $tag = $character_decomposition_tag{$tag}; $decomp = join( ", 0x", @fields ); $decomp = "0x".$decomp; $decomposition{$code} = $decomp; $decomposition_tag{$code} = $tag; $decomposition_pos{$code} = $position; $len = scalar(@fields); $decomposition_len{$code} = $len;# we use canonical decompositions longer than 1 char# and all arabic ligatures for the ligature table if(($len > 1 and $tag == 1) or ($tag > 3 and $tag < 8)) {# ligature to add... $start = shift @fields; $ligature{$start} = $ligature{$start}." ".$code; }# adjust position if($len != 0) { $position += $len + 3; }}open IN2, "ArabicShaping.txt";$position = 1;while (<IN2>) { @fields = split /;/; $code = shift @fields; $dummy = shift @fields; $join = shift @fields; $join =~ s/ //g; $join = $joining_code{$join}; $joining{$code}=$join;}# Build pages...#$rowtable_txt = "static const Q_UINT8 * const unicode_info[256] = {";for $row ( 0..255 ) { $nonzero=0; $txt = ""; for $cell ( 0..255 ) { $code = sprintf("%02X%02X",$row,$cell); $info = $category{$code}; $info = 0 if !defined $info; $txt .= "\n " if $cell%8 == 0; $txt .= "$info, "; } $therow = $row{$txt}; if ( !defined $therow ) { $size+=256; $therow = "ui_".sprintf("%02X",$row); $rowtext{$therow} = "static const Q_UINT8 ${therow}[] = {$txt\n};\n\n"; $row{$txt}=$therow; } $rowtable_txt .= "\n " if $row%8 == 0; $rowtable_txt .= "$therow, ";}print "// START OF GENERATED DATA\n\n";print "#ifndef QT_NO_UNICODETABLES\n\n";# Print pages...#for $r ( sort keys %rowtext ) { print $rowtext{$r};}print "$rowtable_txt\n};\n";$size += 256*4;print "// $size bytes\n\n";# Build decomposition tables#$rowtable_txt = "static const Q_UINT16 * const decomposition_info[256] = {";$table_txt = "static const Q_UINT16 decomposition_map[] = {\n 0,\n";for $row ( 0..255 ) { $nonzero=0; $txt = ""; for $cell ( 0..255 ) { $code = sprintf("%02X%02X",$row,$cell); $txt .= "\n " if $cell%8 == 0; if( $decomposition_tag{$code} != 0 ) { $txt .= " $decomposition_pos{$code},"; $table_txt .= " $decomposition_tag{$code},"; $table_txt .= " 0x$code,"; $table_txt .= " $decomposition{$code}, 0,\n"; $size += 2 * $decomposition_len{$code} + 6; } else { $txt .= " 0,"; } } $therow = $row{$txt}; if ( !defined $therow ) { $size+=512; $therow = "di_".sprintf("%02X",$row); $dec_rowtext{$therow} = "static const Q_UINT16 ${therow}[] = {$txt\n};\n\n"; $row{$txt}=$therow; } $rowtable_txt .= "\n " if $row%8 == 0; $rowtable_txt .= "$therow, ";}# Print decomposition tables#print "$table_txt\n};\n\n";for $r ( sort keys %dec_rowtext ) { print $dec_rowtext{$r};}print "$rowtable_txt\n};\n";$size += 256*4;print "// $size bytes\n\n";# build ligature tables#$size = 0;$position = 1;$rowtable_txt = "static const Q_UINT16 * const ligature_info[256] = {";$table_txt = "static const Q_UINT16 ligature_map[] = {\n 0,\n";for $lig_row ( 0..255 ) { $nonzero=0; $txt = ""; for $cell ( 0..255 ) { $code = sprintf("%02X%02X",$lig_row,$cell); $txt .= "\n " if $cell%8 == 0; if( defined $ligature{$code} ) { $txt .= " $position,"; @ligature = split(" ", $ligature{$code});# we need to sort ligatures according to their length.# long ones have to come first! @ligature_sort = sort { $decomposition_len{$b} <=> $decomposition_len{$a} } @ligature;# now replace each code by it's position in# the decomposition map. undef(@lig_pos); for $n (@ligature_sort) { push(@lig_pos, $decomposition_pos{$n}); }# debug info if( 0 ) { print "ligatures: $ligature{$code}\n"; $sort = join(" ", @ligature_sort); print "sorted : $sort\n"; } $lig = join(", ", @lig_pos); $table_txt .= " $lig, 0,\n"; $size += 2 * scalar(@ligature) + 2; $position += scalar(@ligature) + 1; } else { $txt .= " 0,"; } } $therow = $lig_row{$txt}; if ( !defined $therow ) { $size+=512; $therow = "li_".sprintf("%02X",$lig_row); $lig_rowtext{$therow} = "static const Q_UINT16 ${therow}[] = {$txt\n};\n\n"; $lig_row{$txt}=$therow; } $rowtable_txt .= "\n " if $lig_row%8 == 0; $rowtable_txt .= "$therow, ";}# Print ligature tables#print "$table_txt\n};\n\n";for $r ( sort keys %lig_rowtext ) { print $lig_rowtext{$r};}print "$rowtable_txt\n};\n";$size += 256*4;print "// $size bytes\n\n";# Build direction/joining/mirrored pages...#$rowtable_txt = "static const Q_UINT8 * const direction_info[256] = {";for $dir_row ( 0..255 ) { $nonzero=0; $txt = ""; for $cell ( 0..255 ) { $code = sprintf("%02X%02X",$dir_row,$cell); $dir = $bidi_category{$code}; $dir = 0 if !defined $dir; $join = $joining{$code}; $join = 0 if !defined $join; $mirr = $mirrored{$code}; $mirr = 0 if !defined $mirr; $info = $dir + 32*$join + 128*$mirr; $txt .= "\n " if $cell%8 == 0; $txt .= "$info, "; } $therow = $dir_row{$txt}; if ( !defined $therow ) { $size+=256; $therow = "dir_".sprintf("%02X",$dir_row); $dir_rowtext{$therow} = "static const Q_UINT8 ${therow}[] = {$txt\n};\n\n"; $dir_row{$txt}=$therow; } $rowtable_txt .= "\n " if $dir_row%8 == 0; $rowtable_txt .= "$therow, ";}# Print pages...#for $r ( sort keys %dir_rowtext ) { print $dir_rowtext{$r};}print "$rowtable_txt\n};\n";$size += 256*4;print "// $size bytes\n\n";print "#endif\n\n";print "// END OF GENERATED DATA\n\n";__END__*/// START OF GENERATED DATAstatic const Q_UINT8 ui_00[] = { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 7, 26, 26, 26, 28, 26, 26, 26, 22, 23, 26, 27, 26, 21, 26, 26, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 26, 26, 27, 27, 27, 26, 26, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 22, 26, 23, 29, 20, 29, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 22, 27, 23, 27, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 7, 26, 28, 28, 28, 28, 30, 30, 29, 30, 16, 24, 27, 21, 30, 29, 30, 27, 6, 6, 29, 16, 30, 26, 29, 6, 16, 25, 6, 6, 6, 26, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 27, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 27, 16, 16, 16, 16, 16, 16, 16, 16,};#ifndef QT_NO_UNICODETABLESstatic const Q_UINT8 ui_01[] = { 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 15, 16, 15, 16, 15, 16, 16, 16, 15, 15, 16, 15, 16, 15, 15, 16, 15, 15, 15, 16, 16, 15, 15, 15, 15, 16, 15, 15, 16, 15, 15, 15, 16, 16, 16, 15, 15, 16, 15, 15, 16, 15, 16, 15, 16, 15, 15, 16, 15, 16, 16, 15, 16, 15, 15, 16, 15, 15, 15, 16, 15, 16, 15, 15, 16, 16, 19, 15, 16, 16, 16, 19, 19, 19, 19, 15, 17, 16, 15, 17, 16, 15, 17, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 15, 16, 16, 15, 17, 16, 15, 16, 15, 15, 15, 16, 15, 16, 15, 16, 15, 16,};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -