/*
* Copyright 2001-2004 Unicode, Inc.
*
* Disclaimer
*
* This source code is provided as is by Unicode, Inc. No claims are
* made as to fitness for any particular purpose. No warranties of any
* kind are expressed or implied. The recipient agrees to determine
* applicability of information provided. If this file has been
* purchased on magnetic or optical media from Unicode, Inc., the
* sole remedy for any claim will be exchange of defective media
* within 90 days of receipt.
*
* Limitations on Rights to Redistribute This Code
*
* Unicode, Inc. hereby grants the right to freely use the information
* supplied in this file in the creation of products supporting the
* Unicode Standard, and to make copies of this file in any form
* for internal or external distribution as long as this notice
* remains attached.
*/
/* ---------------------------------------------------------------------
Conversions between UTF32, UTF-16, and UTF-8. Source code file.
Author: Mark E. Davis, 1994.
Rev History: Rick McGowan, fixes & updates May 2001.
Sept 2001: fixed const & error conditions per
mods suggested by S. Parent & A. Lillich.
June 2002: Tim Dodd added detection and handling of incomplete
source sequences, enhanced error detection, added casts
to eliminate compiler warnings.
July 2003: slight mods to back out aggressive FFFE detection.
Jan 2004: updated switches in from-UTF8 conversions.
Oct 2004: updated to use UNI_MAX_LEGAL_UTF32 in UTF-32 conversions.
See the header file "ConvertUTF.h" for complete documentation.
------------------------------------------------------------------------ */
#include "convert_UTF.h"
#ifdef CVTUTF_DEBUG
#include <stdio.h>
#endif
static const int halfShift = 10; /* used for shifting by 10 bits */
static const UTF32 halfBase = 0x0010000UL;
static const UTF32 halfMask = 0x3FFUL;
#define UNI_SUR_HIGH_START (UTF32)0xD800
#define UNI_SUR_HIGH_END (UTF32)0xDBFF
#define UNI_SUR_LOW_START (UTF32)0xDC00
#define UNI_SUR_LOW_END (UTF32)0xDFFF
#define false 0
#define true 1
/* --------------------------------------------------------------------- */
ConversionResult ConvertUTF32toUTF16 (const UTF32** sourceStart, const UTF32* sourceEnd,
UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags) {
ConversionResult result = conversionOK;
const UTF32* source = *sourceStart;
UTF16* target = *targetStart;
while (source < sourceEnd) {
UTF32 ch;
if (target >= targetEnd) {
result = targetExhausted; break;
}
ch = *source++;
if (ch <= UNI_MAX_BMP) { /* Target is a character <= 0xFFFF */
/* UTF-16 surrogate values are illegal in UTF-32; 0xffff or 0xfffe are both reserved values */
if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
if (flags == strictConversion) {
--source; /* return to the illegal value itself */
result = sourceIllegal;
break;
} else {
*target++ = UNI_REPLACEMENT_CHAR;
}
} else {
*target++ = (UTF16)ch; /* normal case */
}
} else if (ch > UNI_MAX_LEGAL_UTF32) {
if (flags == strictConversion) {
result = sourceIllegal;
} else {
*target++ = UNI_REPLACEMENT_CHAR;
}
} else {
/* target is a character in range 0xFFFF - 0x10FFFF. */
if (target + 1 >= targetEnd) {
--source; /* Back up source pointer! */
result = targetExhausted; break;
}
ch -= halfBase;
*target++ = (UTF16)((ch >> halfShift) + UNI_SUR_HIGH_START);
*target++ = (UTF16)((ch & halfMask) + UNI_SUR_LOW_START);
}
}
*sourceStart = source;
*targetStart = target;
return result;
}
/* --------------------------------------------------------------------- */
ConversionResult ConvertUTF16toUTF32 (const UTF16** sourceStart, const UTF16* sourceEnd,
UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags) {
ConversionResult result = conversionOK;
const UTF16* source = *sourceStart;
UTF32* target = *targetStart;
UTF32 ch, ch2;
while (source < sourceEnd) {
const UTF16* oldSource = source; /* In case we have to back up because of target overflow. */
ch = *source++;
/* If we have a surrogate pair, convert to UTF32 first. */
if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END) {
/* If the 16 bits following the high surrogate are in the source buffer... */
if (source < sourceEnd) {
ch2 = *source;
/* If it's a low surrogate, convert to UTF32. */
if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END) {
ch = ((ch - UNI_SUR_HIGH_START) << halfShift)
+ (ch2 - UNI_SUR_LOW_START) + halfBase;
++source;
} else if (flags == strictConversion) { /* it's an unpaired high surrogate */
--source; /* return to the illegal value itself */
result = sourceIllegal;
break;
}
} else { /* We don't have the 16 bits following the high surrogate. */
--source; /* return to the high surrogate */
result = sourceExhausted;
break;
}
} else if (flags == strictConversion) {
/* UTF-16 surrogate values are illegal in UTF-32 */
if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END) {
--source; /* return to the illegal value itself */
result = sourceIllegal;
break;
}
}
if (target >= targetEnd) {
source = oldSource; /* Back up source pointer! */
result = targetExhausted; break;
}
*target++ = ch;
}
*sourceStart = source;
*targetStart = target;
#ifdef CVTUTF_DEBUG
if (result == sourceIllegal) {
fprintf(stderr, "ConvertUTF16toUTF32 illegal seq 0x%04x,%04x\n", ch, ch2);
fflush(stderr);
}
#endif
return result;
}
/* --------------------------------------------------------------------- */
/*
* Index into the table below with the first byte of a UTF-8 sequence to
* get the number of trailing bytes that are supposed to follow it.
* Note that *legal* UTF-8 values can't have 4 or 5-bytes. The table is
* left as-is for anyone who may want to do such conversion, which was
* allowed in earlier algorithms.
*/
static const char trailingBytesForUTF8[256] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
};
/*
* Magic values subtracted from a buffer value during UTF8 conversion.
* This table contains as many values as there might be trailing bytes
* in a UTF-8 sequence.
*/
static const UTF32 offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, 0x000E2080UL,
0x03C82080UL, 0xFA082080UL, 0x82082080UL };
/*
* Once the bits are split out into bytes of UTF-8, this is a mask OR-ed
* into the first byte, depending on how many bytes follow. There are
* as many entries in this table as there are UTF-8 sequence types.
* (I.e., one byte sequence, two byte... etc.). Remember that sequencs
* for *legal* UTF-8 will be 4 or fewer bytes total.
*/
static const UTF8 firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
/* --------------------------------------------------------------------- */
/* The interface converts a whole buffer to avoid function-call overhead.
* Constants have been gathered. Loops & conditionals have been removed as
* much as possible for efficiency, in favor of drop-through switches.
* (See "Note A" at the bottom of the file for equivalent code.)
* If your compiler supports it, the "isLegalUTF8" call can be turned
* into an inline
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
如果你开发了一个需要发布到用户电脑上的客户端小程序,你当然不会在程序的可执行文件中包含符号表之类的调试信息,你当然也不想麻烦你的用户在程序崩溃时把计算机抱来给你检修——但你却一定想知道,万一你的程序在用户的计算机上崩溃,该如何了解崩溃那一刻程序的状态,特别是对程序调试至关重要的堆栈状态呢? 试试Breakpad吧,无论你的程序运行在Windows平台,Mac OS X平台还是Linux平台,Breakpad都可以帮你截获程序崩溃那一刹那的重要信息。利用Breakpad,你可以在程序中加入自己的灾难响应装置,就像为程序加装安全气囊。你可以获取程序崩溃时可能为后期调试提供帮助的所有重要信息。你还可以在自己的灾难响应代码中把这些重要信息发回给自己,然后利用符号分析和调试工具,在不需要接触用户环境的情况下找到程序的错误原因。
资源推荐
资源详情
资源评论
收起资源包目录
Google Breakpad 源代码 (541个子文件)
configure.ac 3KB
all-wcprops 5KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 969B
all-wcprops 639B
all-wcprops 636B
all-wcprops 589B
all-wcprops 554B
all-wcprops 534B
all-wcprops 511B
all-wcprops 510B
all-wcprops 503B
all-wcprops 496B
all-wcprops 466B
all-wcprops 457B
all-wcprops 444B
all-wcprops 335B
all-wcprops 324B
all-wcprops 314B
all-wcprops 312B
all-wcprops 310B
all-wcprops 260B
all-wcprops 254B
all-wcprops 248B
all-wcprops 248B
all-wcprops 210B
all-wcprops 206B
all-wcprops 158B
all-wcprops 108B
all-wcprops 107B
all-wcprops 95B
all-wcprops 84B
all-wcprops 83B
all-wcprops 82B
all-wcprops 81B
all-wcprops 80B
all-wcprops 79B
all-wcprops 78B
all-wcprops 74B
Makefile.am 11KB
AUTHORS 22B
convert_UTF.c 19KB
md5.c 8KB
minidump.cc 103KB
minidump_processor.cc 30KB
minidump_generator.cc 27KB
pdb_source_line_writer.cc 26KB
minidump_generator.cc 25KB
exception_handler.cc 23KB
basic_source_line_resolver.cc 21KB
dump_symbols.cc 21KB
exception_handler.cc 21KB
stackwalker_x86.cc 21KB
range_map_unittest.cc 19KB
minidump_stackwalk.cc 19KB
ms_symbol_server_converter.cc 17KB
minidump_generator.cc 15KB
linux_thread.cc 13KB
http_upload.cc 12KB
postfix_evaluator_unittest.cc 12KB
stackwalker_selftest.cc 12KB
dynamic_images.cc 11KB
macho_id.cc 10KB
exception_handler.cc 9KB
solaris_lwp.cc 9KB
exception_handler.cc 9KB
linux_thread_test.cc 9KB
minidump_processor_unittest.cc 8KB
sym_upload.cc 8KB
minidump_file_writer.cc 8KB
contained_range_map_unittest.cc 8KB
basic_source_line_resolver_unittest.cc 7KB
symupload.cc 7KB
macho_walker.cc 7KB
address_map_unittest.cc 7KB
stackwalker.cc 6KB
minidump_file_writer_unittest.cc 6KB
string_conversion.cc 6KB
stackwalker_ppc.cc 6KB
file_id.cc 6KB
http_upload.cc 5KB
minidump_upload.cc 5KB
file_id.cc 5KB
simple_symbol_supplier.cc 5KB
basic_code_modules.cc 4KB
crash_report_sender.cc 4KB
minidump_dump.cc 4KB
exception_handler_test.cc 4KB
pathname_stripper_unittest.cc 4KB
protected_memory_allocator.cc 4KB
macho_utilities.cc 3KB
exception_handler_test.cc 3KB
file_id.cc 3KB
共 541 条
- 1
- 2
- 3
- 4
- 5
- 6
吹泡泡的小猫
- 粉丝: 9234
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页