学习LCMapString和LCMapStringEx
LCMapStringEx: http://msdn.microsoft.com/en-us/library/windows/desktop/dd318702(v=vs.85).aspx
For a locale specified by name, maps an input character string to another using a specified transformation, or generates a sort key for the input string.
也就是说对某个指定的Locale,将一个输入的字符使用某种转换映射为另外一个字符,或者对输入的字符串产生一个sort key。具体支持哪些转换呢,就要从理解其第2个参数开始:
Flag | Meaning | 注解 |
LCMAP_BYTEREV | Use byte reversal. For example, if the application passes in 0x3450 0x4822, the result is 0x5034 0x2248. | 字节转置,也许在大小端时会用到 |
LCMAP_FULLWIDTH | Use Unicode (wide) characters where applicable. This flag and LCMAP_HALFWIDTH are mutually exclusive. | 转换为全角字符 |
LCMAP_HALFWIDTH | Use narrow characters where applicable. This flag and LCMAP_FULLWIDTH are mutually exclusive. | 转换为半角字符 |
LCMAP_HIRAGANA | Map all katakana characters to hiragana. This flag and LCMAP_KATAKANA are mutually exclusive. | 将平假名转换为片假名 |
LCMAP_KATAKANA | Map all hiragana characters to katakana. This flag and LCMAP_HIRAGANA are mutually exclusive. | 将片假名转换为平假名 |
LCMAP_LINGUISTIC_CASING | Use linguistic rules for casing, instead of file system rules (default). This flag is valid with LCMAP_LOWERCASE or LCMAP_UPPERCASE only. |
土耳其语时会用到,不太清楚,可以看看 http://blogs.msdn.com/b/michkap/archive/2004/12/03/274288.aspx |
LCMAP_LOWERCASE | For locales and scripts capable of handling uppercase and lowercase, map all characters to lowercase. | 转换为小写 |
LCMAP_SIMPLIFIED_CHINESE | Map traditional Chinese characters to simplified Chinese characters. This flag and LCMAP_TRADITIONAL_CHINESE are mutually exclusive. | 将繁体中文转换为简体中文 |
LCMAP_SORTKEY | Produce a normalized sort key. If the LCMAP_SORTKEY flag is not specified, the function performs string mapping. For details of sort key generation and string mapping, see the Remarks section. | |
LCMAP_TITLECASE | Windows 7: Map all characters to title case, in which the first letter of each major word is capitalized. | 每个单词的第一个字母大写 |
LCMAP_TRADITIONAL_CHINESE | Map simplified Chinese characters to traditional Chinese characters. This flag and LCMAP_SIMPLIFIED_CHINESE are mutually exclusive. | 将简体中文转换为繁体中文 |
LCMAP_UPPERCASE | For locales and scripts capable of handling uppercase and lowercase, map all characters to uppercase. | 转换为大写 |
下面的Flag可以单独用,互相用,或者跟LCMAP_SORTKEY and/or LCMAP_BYTEREV使用,但是不能跟上面的结合使用。
Flag | Meaning | 注释 |
NORM_IGNORENONSPACE |
Ignore nonspacing characters. For many scripts (notably Latin scripts), NORM_IGNORENONSPACE coincides with LINGUISTIC_IGNOREDIACRITIC. Note NORM_IGNORENONSPACE ignores any secondary distinction, whether it is a diacritic or not. Scripts for Korean, Japanese, Chinese, and Indic languages, among others, use this distinction for purposes other than diacritics. LINGUISTIC_IGNOREDIACRITIC causes the function to ignore only actual diacritics, instead of ignoring the second sorting weight. |
|
NORM_IGNORESYMBOLS | Ignore symbols and punctuation |
下面的参数只能跟LCMAP_SORTKEY一起使用
Flag | Meaning | 注释 |
LINGUISTIC_IGNORECASE | Ignore case, as linguistically appropriate. | 如果语言适用,忽略大小写 |
LINGUISTIC_IGNOREDIACRITIC |
Ignore nonspacing characters, as linguistically appropriate. Note This flag does not always produce predictable results when used with decomposed characters, that is, characters in which a base character and one or more nonspacing characters each have distinct code point values. |
如果语言适用,忽略非空白字符 |
NORM_IGNORECASE |
Ignore case. For many scripts (notably Latin scripts), NORM_IGNORECASE coincides with LINGUISTIC_IGNORECASE. Note NORM_IGNORECASE ignores any tertiary distinction, whether it is actually linguistic case or not. For example, in Arabic and Indic scripts, this flag distinguishes alternate forms of a character, but the differences do not correspond to linguistic case. LINGUISTIC_IGNORECASE causes the function to ignore only actual linguistic casing, instead of ignoring the third sorting weight. Note For double-byte character set (DBCS) locales, NORM_IGNORECASE has an effect on all Unicode characters as well as narrow (one-byte) characters, including Greek and Cyrillic characters. |
忽略大小写 |
NORM_IGNOREKANATYPE | Do not differentiate between hiragana and katakana characters. Corresponding hiragana and katakana characters compare as equal. | 不区分平假名和片假名 |
NORM_IGNOREWIDTH | Ignore the difference between half-width and full-width characters, for example, C a t == cat. The full-width form is a formatting distinction used in Chinese and Japanese scripts. | 不区分半角和全角 |
NORM_LINGUISTIC_CASING | Use linguistic rules for casing, instead of file system rules (default). | |
SORT_DIGITSASNUMBERS | Windows 7: Treat digits as numbers during sorting, for example, sort "2" before "10". | 将数字字符为数字,英语解释的更好 |
SORT_STRINGSORT | Treat punctuation the same as symbols. | 将标点符号作为symbol |
关于generate Sorting key还得看看http://msdn.microsoft.com/en-us/library/windows/desktop/dd318144(v=vs.85).aspx,总结入下:
sorting key 是对特定字符串在制定Locale中生成的一种二进制的表示形式,这个二进制的表示可以表达这个字符串在这个Locale中进行Sort的行为,如果要比较两个字符串,可以为他们分别生成sorting key,然后使用memcmp进行比较。
#include <memory>
#include <Windows.h> int main(int argc, char **argv)
{
LPCWSTR pSrc = L"我爱北京天安门";
LPCWSTR pSrc2 = L"我爱北京天安门金山";
LPWSTR pDest = new WCHAR[200];
memset(pDest, 0, sizeof(WCHAR) * 200);
int result = LCMapStringEx(L"zh-CN" , LCMAP_SORTKEY|LCMAP_BYTEREV,pSrc, 7, pDest,200,NULL, NULL, 0);
int result2 = LCMapStringEx(L"zh-CN" , LCMAP_SORTKEY,pSrc2, 9, pDest,200,NULL, NULL, 0);
//int result = LCMapString (0x041d,LCMAP_SORTKEY,pSrc, 7,pDest,11);
if(result == 0)
{
DWORD lasterror = GetLastError();
if(lasterror == ERROR_INVALID_FLAGS)
printf("ERROR_INVALID_FLAGS");
else if(lasterror == ERROR_INSUFFICIENT_BUFFER)
printf("ERROR_INSUFFICIENT_BUFFER");
else if(lasterror == ERROR_INVALID_PARAMETER)
printf("ERROR_INVALID_PARAMETER");
}
}
为“我爱北京天安门”生成的sorting key是ce c6 13 c0 11 34 c0 83 0d c6 19 25 cd e6 0d c0 15 10 c8 aa 0d 01 01 01 01 00,而为“我爱北京天安门金山”生成的sorting key是ce c6 13 c0 11 34 c0 83 0d c6 19 25 cd e6 0d c0 15 10 c8 aa 0d c6 0e 2e cc 82 0d 01 01 01 01 00
学习LCMapString和LCMapStringEx的更多相关文章
- LCMapString/LCMapStringEx实现简体字、繁体字的转换。
c#环境下想要最小程度不使用第三方库.程序性能,于是选择了这个Windows API. 转载自https://coolong124220.nidbox.com/diary/read/8045380 对 ...
- 从直播编程到直播教育:LiveEdu.tv开启多元化的在线学习直播时代
2015年9月,一个叫Livecoding.tv的网站在互联网上引起了编程界的注意.缘于Pingwest品玩的一位编辑在上网时无意中发现了这个网站,并写了一篇文章<一个比直播睡觉更奇怪的网站:直 ...
- Angular2学习笔记(1)
Angular2学习笔记(1) 1. 写在前面 之前基于Electron写过一个Markdown编辑器.就其功能而言,主要功能已经实现,一些小的不影响使用的功能由于时间关系还没有完成:但就代码而言,之 ...
- ABP入门系列(1)——学习Abp框架之实操演练
作为.Net工地搬砖长工一名,一直致力于挖坑(Bug)填坑(Debug),但技术却不见长进.也曾热情于新技术的学习,憧憬过成为技术大拿.从前端到后端,从bootstrap到javascript,从py ...
- 消息队列——RabbitMQ学习笔记
消息队列--RabbitMQ学习笔记 1. 写在前面 昨天简单学习了一个消息队列项目--RabbitMQ,今天趁热打铁,将学到的东西记录下来. 学习的资料主要是官网给出的6个基本的消息发送/接收模型, ...
- js学习笔记:webpack基础入门(一)
之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...
- Unity3d学习 制作地形
这周学习了如何在unity中制作地形,就是在一个Terrain的对象上盖几座小山,在山底种几棵树,那就讲一下如何完成上述内容. 1.在新键得项目的游戏的Hierarchy目录中新键一个Terrain对 ...
- 《Django By Example》第四章 中文 翻译 (个人学习,渣翻)
书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:祝大家新年快乐,这次带来<D ...
- 菜鸟Python学习笔记第一天:关于一些函数库的使用
2017年1月3日 星期二 大一学习一门新的计算机语言真的很难,有时候连函数拼写出错查错都能查半天,没办法,谁让我英语太渣. 关于计算机语言的学习我想还是从C语言学习开始为好,Python有很多语言的 ...
随机推荐
- DialogFragment 自定义弹窗
layout文件 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:a ...
- form表单控件
$("select option[value='" + queryparams['vendor'] + "']").attr("selected&qu ...
- selenium+python笔记11
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: search in mail box "&qu ...
- uploader上传
综述 Uploader是非常强大的异步文件上传组件,支持ajax.iframe.flash三套方案,实现浏览器的全兼容,调用非常简单,内置多套主题支持和常用插件,比如验证.图片预览.进度条等. 广泛应 ...
- (32)odoo中的编码问题
对于全部是英文就不存在问题,但我们常用中文,这样会导致一个棘手的问题 约定: 系统Ubuntu trusty14.04 自带python2.7.6 python2.7.9 自己升级了 升级方法: -- ...
- VirtualBox – Error In supR3HardenedWinReSpawn 问题解决办法
转:http://chenpeng.info/html/3510---------VirtualBox – Error In supR3HardenedWinReSpawn---------<h ...
- discuz核心类库class_core的函数注释
class discuz_core { // 数据库存储引擎 var $db = null; // 内存缓冲object var $mem = null; // 会话 object var $sess ...
- Reorder List [LeetCode]
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do thi ...
- SecureCRT快捷键
ctrl + a : 移动光标到行首ctrl + e :移动光标到行尾crtl + b: 光标前移1个字符crtl + f : 光标后移1个字符 crtl + h : 删除光标之前的一个字符c ...
- jQuery给同一个元素两个点击事件
$(".course-form .course-start img").each(function(i) { $(this).toggle(function(){ $(this). ...