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的更多相关文章

  1. LCMapString/LCMapStringEx实现简体字、繁体字的转换。

    c#环境下想要最小程度不使用第三方库.程序性能,于是选择了这个Windows API. 转载自https://coolong124220.nidbox.com/diary/read/8045380 对 ...

  2. 从直播编程到直播教育:LiveEdu.tv开启多元化的在线学习直播时代

    2015年9月,一个叫Livecoding.tv的网站在互联网上引起了编程界的注意.缘于Pingwest品玩的一位编辑在上网时无意中发现了这个网站,并写了一篇文章<一个比直播睡觉更奇怪的网站:直 ...

  3. Angular2学习笔记(1)

    Angular2学习笔记(1) 1. 写在前面 之前基于Electron写过一个Markdown编辑器.就其功能而言,主要功能已经实现,一些小的不影响使用的功能由于时间关系还没有完成:但就代码而言,之 ...

  4. ABP入门系列(1)——学习Abp框架之实操演练

    作为.Net工地搬砖长工一名,一直致力于挖坑(Bug)填坑(Debug),但技术却不见长进.也曾热情于新技术的学习,憧憬过成为技术大拿.从前端到后端,从bootstrap到javascript,从py ...

  5. 消息队列——RabbitMQ学习笔记

    消息队列--RabbitMQ学习笔记 1. 写在前面 昨天简单学习了一个消息队列项目--RabbitMQ,今天趁热打铁,将学到的东西记录下来. 学习的资料主要是官网给出的6个基本的消息发送/接收模型, ...

  6. js学习笔记:webpack基础入门(一)

    之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...

  7. Unity3d学习 制作地形

    这周学习了如何在unity中制作地形,就是在一个Terrain的对象上盖几座小山,在山底种几棵树,那就讲一下如何完成上述内容. 1.在新键得项目的游戏的Hierarchy目录中新键一个Terrain对 ...

  8. 《Django By Example》第四章 中文 翻译 (个人学习,渣翻)

    书籍出处:https://www.packtpub.com/web-development/django-example 原作者:Antonio Melé (译者注:祝大家新年快乐,这次带来<D ...

  9. 菜鸟Python学习笔记第一天:关于一些函数库的使用

    2017年1月3日 星期二 大一学习一门新的计算机语言真的很难,有时候连函数拼写出错查错都能查半天,没办法,谁让我英语太渣. 关于计算机语言的学习我想还是从C语言学习开始为好,Python有很多语言的 ...

随机推荐

  1. vitamio videoView 用隐藏除videoview的控件,并旋转屏幕方向实现的全屏功能,出现的画面不能填充满videoview(画面不完整)

    使用vitamio 封装的播放器 当切换到全屏模式,有时候会出现播放的画面不是全屏的情况, 全屏时,画面只占左半部分并出现拉伸效果,还显示不全,等等其他情况 阅读分析源代码发现是getHolder() ...

  2. WEB网页插件 如何实现 选择上传图片路径 【高级问题】

    发表于 2010-10-22 12:11 | |只看楼主       按键精灵程序里面的WEB网页插件 如何实现 选择上传图片路径 我想在上传图片的选框设置图片路径为 C:\fakepath\001. ...

  3. mac 下基于firebreath 开发多浏览器支持的浏览器插件

    mac 下基于firebreath 开发多浏览器支持的浏览器插件 首先要区分什么是浏览器扩展和浏览器插件;插件可以像本地程序一样做的更多 一. 关于 firebreath http://www.fir ...

  4. python2 urllib 笔记

    python2 urllib 笔记 import urllib base='http://httpbin.org/' ip=base+'ip' r=urllib.urlopen(ip) print r ...

  5. 基于TBDS的flume异常问题排查过程

    版权声明:本文由王亮原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/214 来源:腾云阁 https://www.qclou ...

  6. crontab在一秒内刷新多次导致部分脚本不生效的问题分析

    版权声明:本文由康中良原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/182 来源:腾云阁 https://www.qclo ...

  7. C/C++深度copy和浅copy

    #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<string. ...

  8. hdu---(1280)前m大的数(计数排序)

    前m大的数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  9. 图片填充UIImageView大小不对

    http://www.2cto.com/kf/201507/412894.html UIView的contentMode属性: 默认为Scale To Fill,会保留view的比例,不会完全按照设定 ...

  10. lucene底层数据结构——FST,针对field使用列存储,delta encode压缩doc ids数组,LZ4压缩算法

    参考: http://www.slideshare.net/lucenerevolution/what-is-inaluceneagrandfinal http://www.slideshare.ne ...