YSTest: chrmap.cpp 源文件

YSTest PreAlpha_b400_20130424 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
chrmap.cpp
浏览该文件的文档.
1 ﻿/*
2 Copyright (C) by Franksoft 2009 - 2011.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #include "CHRLib/chrmap.h"
29
30 CHRLIB_BEGIN
31
32 using namespace CharSet;
33
34 size_t
35 FetchFixedCharWidth(Encoding cp)
36 {
37 switch(cp)
38 {
39 case csASCII:
40 return 1;
41 case csUnicode:
42 case csUTF16BE:
43 case csUTF16LE:
44 case csUTF16:
45 return 2;
46 case csUCS4:
47 case csUTF32:
48 case csUTF32BE:
49 case csUTF32LE:
50 return 4;
51 default:
52 return 0;
53 }
54 }
55
56 size_t
57 FetchMaxCharWidth(Encoding cp)
58 {
59 const auto r = FetchFixedCharWidth(cp);
60
61 return r == 0 ? FetchMaxVariantCharWidth(cp) : r;
62 }
63
64 size_t
65 FetchMaxVariantCharWidth(Encoding cp)
66 {
67 switch(cp)
68 {
69 case csGBK:
70 return 2;
71 case csGB18030:
72 case csUTF8:
73 return 4;
74 default:
75 return 0;
76 }
77 }
78
79 CHRLIB_END
80