学习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有很多语言的 ...
随机推荐
- mysql下sql语句 update 字段=字段+字符串
mysql下sql语句 update 字段=字段+字符串 mysql下sql语句令某字段值等于原值加上一个字符串 update 表明 SET 字段= 'feifei' || 字段; (postgr ...
- linux删除文件未释放空间问题处理
linux删除文件未释放空间问题处理 或者 /根分区满了 (我的根分区是/dev/sda1,/dev/sda1满了) http://blog.csdn.net/donghustone/article/ ...
- [转] Android OkHttp完全解析 是时候来了解OkHttp了
http://blog.csdn.net/lmj623565791/article/details/47911083: 本文出自:[张鸿洋的博客] 一.概述 最近在群里听到各种讨论okhttp的话题, ...
- IEnumerable接口的实现
对象要实现可以迭代需IEnumerable接口并实现GetEnumerator方法.一下简单例子 public class SPEnumerable<T> : IEnumerable { ...
- 20145218 《Java程序设计》第05次实验报告
北京电子科技学院(BESTI)实验报告 课程:Java程序设计 班级:1452 指导教师:娄嘉鹏 实验名称:Java网络编程及安全 一.实验内容 1.掌握Socket程序的编写: 2.掌握密码技术的使 ...
- 谈谈JPA-04-JPA的常用API
JPA相关接口/类: Persistence Persistence 类是用于获取 EntityManagerFactory 实例.该类包含一个名为 createEntityManagerFacto ...
- Spring 框架整理
在web.xml中配置以下内容 <!-- 配置Spring MVC DispatcherServlet --> <servlet> <servlet-name>MV ...
- C++一个简单的类
从基本数据类型说起: 一般情况下,c++中的基本数据类型有int ,char,,,, 但是这些数据类型是有限的,而且还是C++中自带的,缺乏灵活性 于是C++提供了一种定义自定义类型的方式----使用 ...
- 史上最用心的 iOS App 上架流程
题记 麻痹起来嗨!看网上那么多的教程,依然在我心爱的爱屁屁在上架的时候遇到各种 J8 问题,最大的问题就是:Xcode 证书什么的,Provisioning Profile 什么的,Debug 什么的 ...
- java 多线程——quartz 定时调度的例子
java 多线程 目录: Java 多线程——基础知识 Java 多线程 —— synchronized关键字 java 多线程——一个定时调度的例子 java 多线程——quartz 定时调度的例子 ...