/*
* 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.
*/
/* $Id: ConvertUTF.c 8178 2007-08-05 13:55:26Z leonardo $*/
/* ---------------------------------------------------------------------
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 "ConvertUTF.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 function.
*/
/* --------------------------------------------------------------------- */
ConversionRes
没有合适的资源?快使用搜索试试~ 我知道了~
NIM-Duilib-Framework-master 网易duilib ,github不稳定,可以从这下载,集成CEF浏览器
共1141个文件
h:474个
cpp:145个
png:130个
需积分: 0 2 下载量 56 浏览量
2024-11-04
10:14:45
上传
评论
收藏 77.89MB ZIP 举报
温馨提示
NIM_Duilib_Framework-master 网易duilib ,github不稳定,可以从这下载,集成CEF浏览器 duillib学习专栏:https://blog.csdn.net/shuilan0066/category_8007774.html?spm=1001.2014.3001.5482 CEF 学习专栏: https://blog.csdn.net/shuilan0066/category_8126382.html
资源推荐
资源详情
资源评论
收起资源包目录
NIM-Duilib-Framework-master
网易duilib ,github不稳定,可以从这下载,集成CEF浏览器 (1141个子文件)
snapshot_blob.bin 604KB
snapshot_blob.bin 475KB
natives_blob.bin 402KB
natives_blob.bin 402KB
ConvertUTF.c 19KB
cef_message_router.cc 38KB
libcef_dll_wrapper.cc 31KB
v8value_ctocpp.cc 24KB
menu_model_ctocpp.cc 23KB
cef_resource_manager.cc 23KB
browser_host_ctocpp.cc 21KB
dictionary_value_ctocpp.cc 16KB
request_handler_cpptoc.cc 16KB
list_value_ctocpp.cc 14KB
xml_reader_ctocpp.cc 14KB
request_context_ctocpp.cc 13KB
cef_xml_object.cc 12KB
domnode_ctocpp.cc 12KB
command_line_ctocpp.cc 11KB
request_ctocpp.cc 11KB
print_settings_ctocpp.cc 11KB
render_handler_cpptoc.cc 10KB
drag_data_ctocpp.cc 10KB
context_menu_params_ctocpp.cc 10KB
render_process_handler_cpptoc.cc 10KB
browser_ctocpp.cc 10KB
value_ctocpp.cc 10KB
frame_ctocpp.cc 9KB
client_cpptoc.cc 9KB
cef_logging.cc 9KB
sslinfo_ctocpp.cc 8KB
download_item_ctocpp.cc 7KB
modp_b64.cc 7KB
domdocument_ctocpp.cc 7KB
cookie_manager_ctocpp.cc 7KB
life_span_handler_cpptoc.cc 7KB
sslcert_principal_ctocpp.cc 7KB
v8context_ctocpp.cc 7KB
response_ctocpp.cc 6KB
zip_reader_ctocpp.cc 6KB
display_handler_cpptoc.cc 6KB
resource_handler_cpptoc.cc 6KB
context_menu_handler_cpptoc.cc 6KB
cef_stream_resource_handler.cc 5KB
post_data_ctocpp.cc 5KB
jsdialog_handler_cpptoc.cc 5KB
print_handler_cpptoc.cc 5KB
navigation_entry_ctocpp.cc 5KB
urlrequest_client_cpptoc.cc 5KB
post_data_element_ctocpp.cc 5KB
binary_value_ctocpp.cc 4KB
stream_reader_ctocpp.cc 4KB
urlrequest_ctocpp.cc 4KB
resource_bundle_handler_cpptoc.cc 4KB
cef_zip_archive.cc 4KB
v8stack_frame_ctocpp.cc 4KB
v8exception_ctocpp.cc 4KB
task_runner_ctocpp.cc 4KB
load_handler_cpptoc.cc 4KB
app_cpptoc.cc 4KB
stream_writer_ctocpp.cc 4KB
v8accessor_cpptoc.cc 4KB
browser_process_handler_cpptoc.cc 4KB
process_message_ctocpp.cc 4KB
keyboard_handler_cpptoc.cc 4KB
download_handler_cpptoc.cc 4KB
atomicops_internals_x86_gcc.cc 3KB
cef_atomicops_x86_gcc.cc 3KB
v8handler_cpptoc.cc 3KB
response_filter_cpptoc.cc 3KB
write_handler_cpptoc.cc 3KB
request_context_handler_cpptoc.cc 3KB
read_handler_cpptoc.cc 3KB
geolocation_handler_cpptoc.cc 3KB
drag_handler_cpptoc.cc 3KB
resource_bundle_ctocpp.cc 3KB
web_plugin_info_ctocpp.cc 3KB
focus_handler_cpptoc.cc 3KB
dialog_handler_cpptoc.cc 3KB
v8stack_trace_ctocpp.cc 3KB
scheme_handler_factory_cpptoc.cc 3KB
file_dialog_callback_ctocpp.cc 3KB
cookie_visitor_cpptoc.cc 2KB
run_file_dialog_callback_cpptoc.cc 2KB
cef_lock_impl.cc 2KB
transfer_util.cc 2KB
find_handler_cpptoc.cc 2KB
cef_thread_collision_warner.cc 2KB
download_item_callback_ctocpp.cc 2KB
navigation_entry_visitor_cpptoc.cc 2KB
get_geolocation_callback_cpptoc.cc 2KB
print_dialog_callback_ctocpp.cc 2KB
auth_callback_ctocpp.cc 2KB
cef_string16.cc 2KB
web_plugin_info_visitor_cpptoc.cc 2KB
web_plugin_unstable_callback_cpptoc.cc 2KB
resolve_callback_cpptoc.cc 2KB
run_context_menu_callback_ctocpp.cc 2KB
scheme_registrar_ctocpp.cc 2KB
end_tracing_callback_cpptoc.cc 2KB
共 1141 条
- 1
- 2
- 3
- 4
- 5
- 6
- 12
资源评论
清水迎朝阳
- 粉丝: 2184
- 资源: 99
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 《铭仕基本法》(2006年定稿版)-17页.doc
- 海尔企业文化手册.doc
- xx有限公司企业文化手册.doc
- 【案例分析】企业文化案例精选.doc
- 陕西省地方电力集团公司企业文化手册道德礼仪规范.doc
- 微信小程序 实现计算器代码
- 01-【目标体系构建】-企业文化建设规划与实施细则方案撰写指导说明.doc
- 03-【目标体系构建】-企业文化建设工作任务分解与工作推进表.docx
- 02-【目标体系构建】-企业文化建设三年实施规划甘特图.docx
- 04-【识别体系构建】-员工行为规范制定指导书.doc
- 07-【保障体系构建】-职务说明书——企业文化专员.doc
- 06-【保障体系构建】-职务说明书——企业文化建设职能部门(负责人).doc
- 08-【保障体系构建】-企业文化建设经费预算表(年度).doc.docx
- 12-【保障体系构建】-企业文化培训成本费用预算表.doc.docx
- 10-【保障体系构建】-企业文化培训效果综合评估表.doc.docx
- 11-【保障体系构建】-企业文化培训计划表.doc.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功