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. parent relation column can't be updated LESSON_EXTENDED_ATTRIBUTE->LESSON_ID

    MyCat  中 作为分片的主键不允许更新 , 需要设置为null,调用updateSelectiveByPrimaryKey来更新数据 parent relation column can't be ...

  2. 一个最简html5文档来说明html5的新特性和写法

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="utf-8&quo ...

  3. fushioncharts的使用教程

    FusionCharts 是使用javascript 实现统计图表的js组件:其官网地址:http://www.fusioncharts.com.其早期版本FusionCharts Free 是基于f ...

  4. is(C# 参考)

    检查对象是否与给定类型兼容. 例如,下面的代码可以确定对象是否为 MyObject 类型的一个实例,或者对象是否为从 MyObject 派生的一个类型:     if (obj is MyObject ...

  5. js时间显示设置

    //对日期中部分小于10的数字前边添加0 function zero(s){ return s < 10 ? '0' + s: s; } var date=new Date(), year = ...

  6. var isObj = length === undefined || i

    这个其实是因为你前面那个===是肯定为false导致的,所以执行到了i那一步了var length=undefined;var a=length===undefined || i;这样你不定义i也是不 ...

  7. 默认选择radio的第一个

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. JavaWeb基础:Servlet Response

    ServletResponse简介 ServletResponse代表浏览器输出,它提供所有HttpResponse的设置接口,可以设置HttpResponse的响应状态,响应头和响应内容. 生命周期 ...

  9. 让ie678支持css一些属性及html标签

    昨天写的一个页面,用的css3及html5的一些样式与标签,在ie8下看是没有效果的,然后就在晚上查找了一下如何能让ie8也能实现这些效果. 1.添加respond.js文件,Respond.js让I ...

  10. 在jsp页面中实现格式化数字,百分比,货币

    当时的要求是在jsp页面中计算百分比 实现方法 1.引入Jstl的fmt指令 <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" ...