Documentation
¶
Overview ¶
Detecting and Decode for Japanese encoding
Supported Encoding ¶
- Shift_JIS
- EUC-JP
- JIS(ISO-2022-JP)
- UTF-8
- UTF-8(with BOM)
- UTF-16
- UTF-16(with BOM)
- UTF-16(Big Endian)
- UTF-16(Big Endian with BOM)
To detect encoding exactly, use follow encoding:
- JIS
- UTF-8(with BOM)
- UTF-16(with BOM)
- UTF-16(Big Endian with BOM)
- UTF-16(Little Endian containing ASCII char)
- UTF-16(Big Endian containing ASCII char)
Other encodings are not accurate, just pick the one that is more likely.
Index ¶
Examples ¶
Constants ¶
View Source
const ( // 不明 EncodingUnknown = "" // Shift_JIS EncodingShiftJIS = "Shift_JIS" // JIS EncodingJIS = "ISO-2022-JP" // EUC EncodingEUCJP = "EUC-JP" // UTF-8 EncodingUTF8 = "UTF-8" // UTF-8(BOM付) EncodingUTF8BOM = "UTF-8BOM" // UTF-16(BOM無し:リトルエンディアン) EncodingUTF16LE = "UTF-16LE" // UTF-16(BOM無し:リトルエンディアン) EncodingUTF16BE = "UTF-16BE" // UTF-16(BOM有り:リトルエンディアン) EncodingUTF16LEBOM = "UTF-16LEBOM" // UTF-16(BOM有り:ビッグエンディアン) EncodingUTF16BEBOM = "UTF-16BEBOM" )
エンコーディング
Variables ¶
View Source
var ( // エンコーディングの検出に失敗 ErrUnknown = errors.New("unknown encoding") // バイナリファイルっぽい ErrPossiblyBinary = errors.New("possibly binary") )
エラー定義
Functions ¶
func Decode ¶
エンコーディングの自動判別とデコード
SJIS, EUC-JP などの文字列のバイト配列 byteArray を文字列に変換します。 失敗した場合、string(byteArray) と ErrUnknown/ErrPossiblyBinary エラーを返します。
Example ¶
Decode() のサンプル
package main
import (
"fmt"
"github.com/juneysec/jpdec"
)
func main() {
byteArray := []byte{0x82, 0xB1, 0x82, 0xF1, 0x82, 0xC9, 0x82, 0xBF, 0x82, 0xCD}
str, _ := jpdec.Decode(byteArray)
fmt.Println(str)
}
Output: こんにちは
func DetectEncoding ¶
エンコーディングの検出
エンコーディングを示す文字列である EncodingXxx 定数のいずれかを返します。 検出に失敗した場合は EncodingUnknown と ErrUnknown/ErrPossiblyBinary エラーを返します。
Example ¶
DetectEncoding() のサンプル
package main
import (
"fmt"
"github.com/juneysec/jpdec"
)
func main() {
byteArray := []byte{0x82, 0xB1, 0x82, 0xF1, 0x82, 0xC9, 0x82, 0xBF, 0x82, 0xCD}
enc, _ := jpdec.DetectEncoding(byteArray)
fmt.Println(enc)
}
Output: Shift_JIS
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.