Class OdfCodePointMappingTable
Provides format-neutral code point mapping table helpers. 提供與格式無關的碼位對照表輔助功能。
public static class OdfCodePointMappingTable
- Inheritance
-
OdfCodePointMappingTable
- Inherited Members
Remarks
Use ParseDelimitedHex(TextReader, char) for line-based tables of delimited hexadecimal pairs (Unicode.org vendor mapping files, UCD-style lists), Parse(TextReader, Func<string, KeyValuePair<int, int>?>) with a line parser delegate for custom line formats, and JSON or spreadsheet sources (for example the Japanese MJ shrink map) should be converted by the caller with a dedicated deserializer. Parsed values are not validated as Unicode scalars because targets may be non-Unicode codes (for example Big5). Both parsers enforce a documented resource budget: at most 4,096 characters per line and 2,000,000 entries per table; exceeding either throws FormatException. Mapping A bounded buffered reader rejects overlong lines before allocating their complete contents. 行式的十六進位對照表(Unicode.org 官方對照檔、UCD 式清單)用 ParseDelimitedHex(TextReader, char); 自訂行格式用帶委派的 Parse(TextReader, Func<string, KeyValuePair<int, int>?>);JSON 或試算表來源(例如日本 MJ 縮退對照)請由呼叫端 以對應的反序列化器自行轉換。解析值不做 Unicode 純量驗證,因為目標值可能是非 Unicode 碼(例如 Big5)。 兩個解析方法皆施行文件化的資源預算:每行至多 4,096 字元、每表至多 2,000,000 筆,超出即擲出 FormatException。解析器使用受限緩衝讀取,在配置完整資料行前即拒絕超長輸入。
Methods
Join(IReadOnlyDictionary<string, int>, IReadOnlyDictionary<string, int>)
Joins two mappings by their shared string keys. 依共用的字串鍵聯結兩份對照表。
public static IReadOnlyDictionary<int, int> Join(IReadOnlyDictionary<string, int> keyToSource, IReadOnlyDictionary<string, int> keyToTarget)
Parameters
keyToSourceIReadOnlyDictionary<string, int>The key-to-source-value mapping. / 鍵至來源值的對應表。
keyToTargetIReadOnlyDictionary<string, int>The key-to-target-value mapping. / 鍵至目標值的對應表。
Returns
- IReadOnlyDictionary<int, int>
A source-value-to-target-value mapping for shared keys. / 共用鍵所形成的來源值至目標值對應表。
Exceptions
- ArgumentNullException
當任一對應表為 null 時擲出
Parse(TextReader, Func<string, KeyValuePair<int, int>?>)
Parses a line-based table with a caller-supplied line parser. 以呼叫端提供的行解析委派解析行式對照表。
public static IReadOnlyDictionary<int, int> Parse(TextReader reader, Func<string, KeyValuePair<int, int>?> lineParser)
Parameters
readerTextReaderThe table content reader. / 對照表內容的讀取器。
lineParserFunc<string, KeyValuePair<int, int>?>The per-line parser returning a mapping pair or null. / 逐行解析並回傳對應項或 null 的委派。
Returns
- IReadOnlyDictionary<int, int>
The parsed mapping. / 解析所得的對應表。
Remarks
Blank lines are skipped; every other line is passed verbatim to lineParser.
Return null to skip a line (for example comments); exceptions thrown by the
delegate propagate unchanged. Duplicate keys keep the last value.
空行會被略過;其餘每行原樣交給 lineParser。回傳 null
可略過該行(例如註解);委派擲出的例外會原樣傳遞。重複鍵保留最後一筆。
Exceptions
- ArgumentNullException
當
reader或lineParser為 null 時擲出- FormatException
當資料行超出行長/筆數資源預算時擲出
ParseDelimitedHex(TextReader, char)
Parses a line-based table of delimited hexadecimal pairs. 解析以分隔字元隔開之十六進位對的行式對照表。
public static IReadOnlyDictionary<int, int> ParseDelimitedHex(TextReader reader, char separator)
Parameters
readerTextReaderThe table content reader. / 對照表內容的讀取器。
separatorcharThe field separator, for example tab or semicolon. / 欄位分隔字元,例如定位或分號。
Returns
- IReadOnlyDictionary<int, int>
The first-field-to-second-field mapping. / 第一欄值至第二欄值的對應表。
Remarks
Lines are trimmed and content after # is treated as a comment; blank lines are skipped.
Each remaining line must contain at least two delimited fields; fields beyond the second are
ignored (Unicode.org mapping files carry a name comment there). Fields may use an optional
0x or U+ prefix. Duplicate keys keep the last value. Range syntax such as
XXXX..YYYY is not supported.
每行先修剪空白並將 # 之後視為註解;空行略過。其餘每行至少須有兩個分隔欄位,
第二欄之後忽略(Unicode.org 對照檔在該處放名稱註解)。欄位可帶選用的 0x 或
U+ 前綴。重複鍵保留最後一筆。不支援 XXXX..YYYY 範圍語法。
Exceptions
- ArgumentNullException
當
reader為 null 時擲出- FormatException
當資料行不符合分隔十六進位格式,或超出行長/筆數資源預算時擲出