コンテンツへスキップ
uencoder

Charset

文字セット(charset)とは、文字から符号位置への対応表であり、符号化形式(UTF-8 など)と組み合わさって、テキストがバイト列になる方法を決定する。

目的

文字と数値の対応を定め、コンピュータがテキストを保存・伝送・表示できるようにする。

メカニズム

文字セットは文字から符号位置への対応(U+4E2D がある常用漢字の符号位置である、など)を定義し、符号化形式は符号位置がバイト列になる方法(UTF-8 では 3 バイト、など)を定義する。HTTP の Content-Type charset パラメータは符号化形式を宣言する。

ユースケース

  • Web ページの文字符号化宣言
  • データベース列の文字セット設定
  • ファイルの符号化検出と変換
  • プロトコルのテキストフィールド符号化

例

  • 入力
    Content-Type: text/html; charset=utf-8
    Output
    The browser decodes the page as UTF-8

    Declaring the encoding form

よくあるエラー

Confusing a character set (e.g., Unicode) with an encoding form (e.g., UTF-8)
Keep them distinct: the character set defines code points, the encoding form defines bytes

関連用語

関連ツール

References