added charset dependencies

This commit is contained in:
Shlomi Noach 2016-09-12 13:32:24 -07:00
parent c3e65d45e2
commit f81b51e9d6
64 changed files with 163002 additions and 0 deletions

209
vendor/golang.org/x/text/encoding/charmap/charmap.go generated vendored Normal file
View File

@ -0,0 +1,209 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:generate go run maketables.go
// Package charmap provides simple character encodings such as IBM Code Page 437
// and Windows 1252.
package charmap // import "golang.org/x/text/encoding/charmap"
import (
"unicode/utf8"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/internal"
"golang.org/x/text/encoding/internal/identifier"
"golang.org/x/text/transform"
)
// These encodings vary only in the way clients should interpret them. Their
// coded character set is identical and a single implementation can be shared.
var (
// ISO8859_6E is the ISO 8859-6E encoding.
ISO8859_6E encoding.Encoding = &iso8859_6E
// ISO8859_6I is the ISO 8859-6I encoding.
ISO8859_6I encoding.Encoding = &iso8859_6I
// ISO8859_8E is the ISO 8859-8E encoding.
ISO8859_8E encoding.Encoding = &iso8859_8E
// ISO8859_8I is the ISO 8859-8I encoding.
ISO8859_8I encoding.Encoding = &iso8859_8I
iso8859_6E = internal.Encoding{
ISO8859_6,
"ISO-8859-6E",
identifier.ISO88596E,
}
iso8859_6I = internal.Encoding{
ISO8859_6,
"ISO-8859-6I",
identifier.ISO88596I,
}
iso8859_8E = internal.Encoding{
ISO8859_8,
"ISO-8859-8E",
identifier.ISO88598E,
}
iso8859_8I = internal.Encoding{
ISO8859_8,
"ISO-8859-8I",
identifier.ISO88598I,
}
)
// All is a list of all defined encodings in this package.
var All = listAll
// TODO: implement these encodings, in order of importance.
// ASCII, ISO8859_1: Rather common. Close to Windows 1252.
// ISO8859_9: Close to Windows 1254.
// utf8Enc holds a rune's UTF-8 encoding in data[:len].
type utf8Enc struct {
len uint8
data [3]byte
}
// charmap describes an 8-bit character set encoding.
type charmap struct {
// name is the encoding's name.
name string
// mib is the encoding type of this encoder.
mib identifier.MIB
// asciiSuperset states whether the encoding is a superset of ASCII.
asciiSuperset bool
// low is the lower bound of the encoded byte for a non-ASCII rune. If
// charmap.asciiSuperset is true then this will be 0x80, otherwise 0x00.
low uint8
// replacement is the encoded replacement character.
replacement byte
// decode is the map from encoded byte to UTF-8.
decode [256]utf8Enc
// encoding is the map from runes to encoded bytes. Each entry is a
// uint32: the high 8 bits are the encoded byte and the low 24 bits are
// the rune. The table entries are sorted by ascending rune.
encode [256]uint32
}
func (m *charmap) NewDecoder() *encoding.Decoder {
return &encoding.Decoder{Transformer: charmapDecoder{charmap: m}}
}
func (m *charmap) NewEncoder() *encoding.Encoder {
return &encoding.Encoder{Transformer: charmapEncoder{charmap: m}}
}
func (m *charmap) String() string {
return m.name
}
func (m *charmap) ID() (mib identifier.MIB, other string) {
return m.mib, ""
}
// charmapDecoder implements transform.Transformer by decoding to UTF-8.
type charmapDecoder struct {
transform.NopResetter
charmap *charmap
}
func (m charmapDecoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
for i, c := range src {
if m.charmap.asciiSuperset && c < utf8.RuneSelf {
if nDst >= len(dst) {
err = transform.ErrShortDst
break
}
dst[nDst] = c
nDst++
nSrc = i + 1
continue
}
decode := &m.charmap.decode[c]
n := int(decode.len)
if nDst+n > len(dst) {
err = transform.ErrShortDst
break
}
// It's 15% faster to avoid calling copy for these tiny slices.
for j := 0; j < n; j++ {
dst[nDst] = decode.data[j]
nDst++
}
nSrc = i + 1
}
return nDst, nSrc, err
}
// charmapEncoder implements transform.Transformer by encoding from UTF-8.
type charmapEncoder struct {
transform.NopResetter
charmap *charmap
}
func (m charmapEncoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
r, size := rune(0), 0
loop:
for nSrc < len(src) {
if nDst >= len(dst) {
err = transform.ErrShortDst
break
}
r = rune(src[nSrc])
// Decode a 1-byte rune.
if r < utf8.RuneSelf {
if m.charmap.asciiSuperset {
nSrc++
dst[nDst] = uint8(r)
nDst++
continue
}
size = 1
} else {
// Decode a multi-byte rune.
r, size = utf8.DecodeRune(src[nSrc:])
if size == 1 {
// All valid runes of size 1 (those below utf8.RuneSelf) were
// handled above. We have invalid UTF-8 or we haven't seen the
// full character yet.
if !atEOF && !utf8.FullRune(src[nSrc:]) {
err = transform.ErrShortSrc
} else {
err = internal.RepertoireError(m.charmap.replacement)
}
break
}
}
// Binary search in [low, high) for that rune in the m.charmap.encode table.
for low, high := int(m.charmap.low), 0x100; ; {
if low >= high {
err = internal.RepertoireError(m.charmap.replacement)
break loop
}
mid := (low + high) / 2
got := m.charmap.encode[mid]
gotRune := rune(got & (1<<24 - 1))
if gotRune < r {
low = mid + 1
} else if gotRune > r {
high = mid
} else {
dst[nDst] = byte(got >> 24)
nDst++
break
}
}
nSrc += size
}
return nDst, nSrc, err
}

View File

@ -0,0 +1,45 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package charmap
import (
"testing"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/internal"
"golang.org/x/text/transform"
)
func dec(e encoding.Encoding) (dir string, t transform.Transformer, err error) {
return "Decode", e.NewDecoder(), nil
}
func enc(e encoding.Encoding) (dir string, t transform.Transformer, err error) {
return "Encode", e.NewEncoder(), internal.ErrASCIIReplacement
}
func TestNonRepertoire(t *testing.T) {
testCases := []struct {
init func(e encoding.Encoding) (string, transform.Transformer, error)
e encoding.Encoding
src, want string
}{
{dec, Windows1252, "\x81", "\ufffd"},
{enc, Windows1252, "갂", ""},
{enc, Windows1252, "a갂", "a"},
{enc, Windows1252, "\u00E9갂", "\xE9"},
}
for _, tc := range testCases {
dir, tr, wantErr := tc.init(tc.e)
dst, _, err := transform.String(tr, tc.src)
if err != wantErr {
t.Errorf("%s %v(%q): got %v; want %v", dir, tc.e, tc.src, err, wantErr)
}
if got := string(dst); got != tc.want {
t.Errorf("%s %v(%q):\ngot %q\nwant %q", dir, tc.e, tc.src, got, tc.want)
}
}
}

524
vendor/golang.org/x/text/encoding/charmap/maketables.go generated vendored Normal file
View File

@ -0,0 +1,524 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
package main
import (
"bufio"
"fmt"
"log"
"net/http"
"sort"
"strings"
"unicode/utf8"
"golang.org/x/text/encoding"
"golang.org/x/text/internal/gen"
)
const ascii = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" +
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" +
` !"#$%&'()*+,-./0123456789:;<=>?` +
`@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_` +
"`abcdefghijklmnopqrstuvwxyz{|}~\u007f"
var encodings = []struct {
name string
mib string
comment string
varName string
replacement byte
mapping string
}{
{
"IBM Code Page 437",
"PC8CodePage437",
"",
"CodePage437",
encoding.ASCIISub,
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM437-2.1.2.ucm",
},
{
"IBM Code Page 850",
"PC850Multilingual",
"",
"CodePage850",
encoding.ASCIISub,
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM850-2.1.2.ucm",
},
{
"IBM Code Page 852",
"PCp852",
"",
"CodePage852",
encoding.ASCIISub,
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM852-2.1.2.ucm",
},
{
"IBM Code Page 855",
"IBM855",
"",
"CodePage855",
encoding.ASCIISub,
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM855-2.1.2.ucm",
},
{
"Windows Code Page 858", // PC latin1 with Euro
"IBM00858",
"",
"CodePage858",
encoding.ASCIISub,
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/windows-858-2000.ucm",
},
{
"IBM Code Page 860",
"IBM860",
"",
"CodePage860",
encoding.ASCIISub,
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM860-2.1.2.ucm",
},
{
"IBM Code Page 862",
"PC862LatinHebrew",
"",
"CodePage862",
encoding.ASCIISub,
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM862-2.1.2.ucm",
},
{
"IBM Code Page 863",
"IBM863",
"",
"CodePage863",
encoding.ASCIISub,
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM863-2.1.2.ucm",
},
{
"IBM Code Page 865",
"IBM865",
"",
"CodePage865",
encoding.ASCIISub,
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/glibc-IBM865-2.1.2.ucm",
},
{
"IBM Code Page 866",
"IBM866",
"",
"CodePage866",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-ibm866.txt",
},
{
"ISO 8859-1",
"ISOLatin1",
"",
"ISO8859_1",
encoding.ASCIISub,
"http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/iso-8859_1-1998.ucm",
},
{
"ISO 8859-2",
"ISOLatin2",
"",
"ISO8859_2",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-iso-8859-2.txt",
},
{
"ISO 8859-3",
"ISOLatin3",
"",
"ISO8859_3",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-iso-8859-3.txt",
},
{
"ISO 8859-4",
"ISOLatin4",
"",
"ISO8859_4",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-iso-8859-4.txt",
},
{
"ISO 8859-5",
"ISOLatinCyrillic",
"",
"ISO8859_5",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-iso-8859-5.txt",
},
{
"ISO 8859-6",
"ISOLatinArabic",
"",
"ISO8859_6,ISO8859_6E,ISO8859_6I",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-iso-8859-6.txt",
},
{
"ISO 8859-7",
"ISOLatinGreek",
"",
"ISO8859_7",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-iso-8859-7.txt",
},
{
"ISO 8859-8",
"ISOLatinHebrew",
"",
"ISO8859_8,ISO8859_8E,ISO8859_8I",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-iso-8859-8.txt",
},
{
"ISO 8859-10",
"ISOLatin6",
"",
"ISO8859_10",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-iso-8859-10.txt",
},
{
"ISO 8859-13",
"ISO885913",
"",
"ISO8859_13",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-iso-8859-13.txt",
},
{
"ISO 8859-14",
"ISO885914",
"",
"ISO8859_14",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-iso-8859-14.txt",
},
{
"ISO 8859-15",
"ISO885915",
"",
"ISO8859_15",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-iso-8859-15.txt",
},
{
"ISO 8859-16",
"ISO885916",
"",
"ISO8859_16",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-iso-8859-16.txt",
},
{
"KOI8-R",
"KOI8R",
"",
"KOI8R",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-koi8-r.txt",
},
{
"KOI8-U",
"KOI8U",
"",
"KOI8U",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-koi8-u.txt",
},
{
"Macintosh",
"Macintosh",
"",
"Macintosh",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-macintosh.txt",
},
{
"Macintosh Cyrillic",
"MacintoshCyrillic",
"",
"MacintoshCyrillic",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-x-mac-cyrillic.txt",
},
{
"Windows 874",
"Windows874",
"",
"Windows874",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-windows-874.txt",
},
{
"Windows 1250",
"Windows1250",
"",
"Windows1250",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-windows-1250.txt",
},
{
"Windows 1251",
"Windows1251",
"",
"Windows1251",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-windows-1251.txt",
},
{
"Windows 1252",
"Windows1252",
"",
"Windows1252",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-windows-1252.txt",
},
{
"Windows 1253",
"Windows1253",
"",
"Windows1253",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-windows-1253.txt",
},
{
"Windows 1254",
"Windows1254",
"",
"Windows1254",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-windows-1254.txt",
},
{
"Windows 1255",
"Windows1255",
"",
"Windows1255",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-windows-1255.txt",
},
{
"Windows 1256",
"Windows1256",
"",
"Windows1256",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-windows-1256.txt",
},
{
"Windows 1257",
"Windows1257",
"",
"Windows1257",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-windows-1257.txt",
},
{
"Windows 1258",
"Windows1258",
"",
"Windows1258",
encoding.ASCIISub,
"http://encoding.spec.whatwg.org/index-windows-1258.txt",
},
{
"X-User-Defined",
"XUserDefined",
"It is defined at http://encoding.spec.whatwg.org/#x-user-defined",
"XUserDefined",
encoding.ASCIISub,
ascii +
"\uf780\uf781\uf782\uf783\uf784\uf785\uf786\uf787" +
"\uf788\uf789\uf78a\uf78b\uf78c\uf78d\uf78e\uf78f" +
"\uf790\uf791\uf792\uf793\uf794\uf795\uf796\uf797" +
"\uf798\uf799\uf79a\uf79b\uf79c\uf79d\uf79e\uf79f" +
"\uf7a0\uf7a1\uf7a2\uf7a3\uf7a4\uf7a5\uf7a6\uf7a7" +
"\uf7a8\uf7a9\uf7aa\uf7ab\uf7ac\uf7ad\uf7ae\uf7af" +
"\uf7b0\uf7b1\uf7b2\uf7b3\uf7b4\uf7b5\uf7b6\uf7b7" +
"\uf7b8\uf7b9\uf7ba\uf7bb\uf7bc\uf7bd\uf7be\uf7bf" +
"\uf7c0\uf7c1\uf7c2\uf7c3\uf7c4\uf7c5\uf7c6\uf7c7" +
"\uf7c8\uf7c9\uf7ca\uf7cb\uf7cc\uf7cd\uf7ce\uf7cf" +
"\uf7d0\uf7d1\uf7d2\uf7d3\uf7d4\uf7d5\uf7d6\uf7d7" +
"\uf7d8\uf7d9\uf7da\uf7db\uf7dc\uf7dd\uf7de\uf7df" +
"\uf7e0\uf7e1\uf7e2\uf7e3\uf7e4\uf7e5\uf7e6\uf7e7" +
"\uf7e8\uf7e9\uf7ea\uf7eb\uf7ec\uf7ed\uf7ee\uf7ef" +
"\uf7f0\uf7f1\uf7f2\uf7f3\uf7f4\uf7f5\uf7f6\uf7f7" +
"\uf7f8\uf7f9\uf7fa\uf7fb\uf7fc\uf7fd\uf7fe\uf7ff",
},
}
func getWHATWG(url string) string {
res, err := http.Get(url)
if err != nil {
log.Fatalf("%q: Get: %v", url, err)
}
defer res.Body.Close()
mapping := make([]rune, 128)
for i := range mapping {
mapping[i] = '\ufffd'
}
scanner := bufio.NewScanner(res.Body)
for scanner.Scan() {
s := strings.TrimSpace(scanner.Text())
if s == "" || s[0] == '#' {
continue
}
x, y := 0, 0
if _, err := fmt.Sscanf(s, "%d\t0x%x", &x, &y); err != nil {
log.Fatalf("could not parse %q", s)
}
if x < 0 || 128 <= x {
log.Fatalf("code %d is out of range", x)
}
if 0x80 <= y && y < 0xa0 {
// We diverge from the WHATWG spec by mapping control characters
// in the range [0x80, 0xa0) to U+FFFD.
continue
}
mapping[x] = rune(y)
}
return ascii + string(mapping)
}
func getUCM(url string) string {
res, err := http.Get(url)
if err != nil {
log.Fatalf("%q: Get: %v", url, err)
}
defer res.Body.Close()
mapping := make([]rune, 256)
for i := range mapping {
mapping[i] = '\ufffd'
}
charsFound := 0
scanner := bufio.NewScanner(res.Body)
for scanner.Scan() {
s := strings.TrimSpace(scanner.Text())
if s == "" || s[0] == '#' {
continue
}
var c byte
var r rune
if _, err := fmt.Sscanf(s, `<U%x> \x%x |0`, &r, &c); err != nil {
continue
}
mapping[c] = r
charsFound++
}
if charsFound < 200 {
log.Fatalf("%q: only %d characters found (wrong page format?)", url, charsFound)
}
return string(mapping)
}
func main() {
mibs := map[string]bool{}
all := []string{}
w := gen.NewCodeWriter()
defer w.WriteGoFile("tables.go", "charmap")
printf := func(s string, a ...interface{}) { fmt.Fprintf(w, s, a...) }
printf("import (\n")
printf("\t\"golang.org/x/text/encoding\"\n")
printf("\t\"golang.org/x/text/encoding/internal/identifier\"\n")
printf(")\n\n")
for _, e := range encodings {
varNames := strings.Split(e.varName, ",")
all = append(all, varNames...)
varName := varNames[0]
switch {
case strings.HasPrefix(e.mapping, "http://encoding.spec.whatwg.org/"):
e.mapping = getWHATWG(e.mapping)
case strings.HasPrefix(e.mapping, "http://source.icu-project.org/repos/icu/data/trunk/charset/data/ucm/"):
e.mapping = getUCM(e.mapping)
}
asciiSuperset, low := strings.HasPrefix(e.mapping, ascii), 0x00
if asciiSuperset {
low = 0x80
}
lvn := 1
if strings.HasPrefix(varName, "ISO") || strings.HasPrefix(varName, "KOI") {
lvn = 3
}
lowerVarName := strings.ToLower(varName[:lvn]) + varName[lvn:]
printf("// %s is the %s encoding.\n", varName, e.name)
if e.comment != "" {
printf("//\n// %s\n", e.comment)
}
printf("var %s encoding.Encoding = &%s\n\nvar %s = charmap{\nname: %q,\n",
varName, lowerVarName, lowerVarName, e.name)
if mibs[e.mib] {
log.Fatalf("MIB type %q declared multiple times.", e.mib)
}
printf("mib: identifier.%s,\n", e.mib)
printf("asciiSuperset: %t,\n", asciiSuperset)
printf("low: 0x%02x,\n", low)
printf("replacement: 0x%02x,\n", e.replacement)
printf("decode: [256]utf8Enc{\n")
i, backMapping := 0, map[rune]byte{}
for _, c := range e.mapping {
if _, ok := backMapping[c]; !ok && c != utf8.RuneError {
backMapping[c] = byte(i)
}
var buf [8]byte
n := utf8.EncodeRune(buf[:], c)
if n > 3 {
panic(fmt.Sprintf("rune %q (%U) is too long", c, c))
}
printf("{%d,[3]byte{0x%02x,0x%02x,0x%02x}},", n, buf[0], buf[1], buf[2])
if i%2 == 1 {
printf("\n")
}
i++
}
printf("},\n")
printf("encode: [256]uint32{\n")
encode := make([]uint32, 0, 256)
for c, i := range backMapping {
encode = append(encode, uint32(i)<<24|uint32(c))
}
sort.Sort(byRune(encode))
for len(encode) < cap(encode) {
encode = append(encode, encode[len(encode)-1])
}
for i, enc := range encode {
printf("0x%08x,", enc)
if i%8 == 7 {
printf("\n")
}
}
printf("},\n}\n")
// Add an estimate of the size of a single charmap{} struct value, which
// includes two 256 elem arrays of 4 bytes and some extra fields, which
// align to 3 uint64s on 64-bit architectures.
w.Size += 2*4*256 + 3*8
}
// TODO: add proper line breaking.
printf("var listAll = []encoding.Encoding{\n%s,\n}\n\n", strings.Join(all, ",\n"))
}
type byRune []uint32
func (b byRune) Len() int { return len(b) }
func (b byRune) Less(i, j int) bool { return b[i]&0xffffff < b[j]&0xffffff }
func (b byRune) Swap(i, j int) { b[i], b[j] = b[j], b[i] }

6706
vendor/golang.org/x/text/encoding/charmap/tables.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

335
vendor/golang.org/x/text/encoding/encoding.go generated vendored Normal file
View File

@ -0,0 +1,335 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package encoding defines an interface for character encodings, such as Shift
// JIS and Windows 1252, that can convert to and from UTF-8.
//
// Encoding implementations are provided in other packages, such as
// golang.org/x/text/encoding/charmap and
// golang.org/x/text/encoding/japanese.
package encoding // import "golang.org/x/text/encoding"
import (
"errors"
"io"
"strconv"
"unicode/utf8"
"golang.org/x/text/encoding/internal/identifier"
"golang.org/x/text/transform"
)
// TODO:
// - There seems to be some inconsistency in when decoders return errors
// and when not. Also documentation seems to suggest they shouldn't return
// errors at all (except for UTF-16).
// - Encoders seem to rely on or at least benefit from the input being in NFC
// normal form. Perhaps add an example how users could prepare their output.
// Encoding is a character set encoding that can be transformed to and from
// UTF-8.
type Encoding interface {
// NewDecoder returns a Decoder.
NewDecoder() *Decoder
// NewEncoder returns an Encoder.
NewEncoder() *Encoder
}
// A Decoder converts bytes to UTF-8. It implements transform.Transformer.
//
// Transforming source bytes that are not of that encoding will not result in an
// error per se. Each byte that cannot be transcoded will be represented in the
// output by the UTF-8 encoding of '\uFFFD', the replacement rune.
type Decoder struct {
transform.Transformer
// This forces external creators of Decoders to use names in struct
// initializers, allowing for future extendibility without having to break
// code.
_ struct{}
}
// Bytes converts the given encoded bytes to UTF-8. It returns the converted
// bytes or nil, err if any error occurred.
func (d *Decoder) Bytes(b []byte) ([]byte, error) {
b, _, err := transform.Bytes(d, b)
if err != nil {
return nil, err
}
return b, nil
}
// String converts the given encoded string to UTF-8. It returns the converted
// string or "", err if any error occurred.
func (d *Decoder) String(s string) (string, error) {
s, _, err := transform.String(d, s)
if err != nil {
return "", err
}
return s, nil
}
// Reader wraps another Reader to decode its bytes.
//
// The Decoder may not be used for any other operation as long as the returned
// Reader is in use.
func (d *Decoder) Reader(r io.Reader) io.Reader {
return transform.NewReader(r, d)
}
// An Encoder converts bytes from UTF-8. It implements transform.Transformer.
//
// Each rune that cannot be transcoded will result in an error. In this case,
// the transform will consume all source byte up to, not including the offending
// rune. Transforming source bytes that are not valid UTF-8 will be replaced by
// `\uFFFD`. To return early with an error instead, use transform.Chain to
// preprocess the data with a UTF8Validator.
type Encoder struct {
transform.Transformer
// This forces external creators of Encoders to use names in struct
// initializers, allowing for future extendibility without having to break
// code.
_ struct{}
}
// Bytes converts bytes from UTF-8. It returns the converted bytes or nil, err if
// any error occurred.
func (e *Encoder) Bytes(b []byte) ([]byte, error) {
b, _, err := transform.Bytes(e, b)
if err != nil {
return nil, err
}
return b, nil
}
// String converts a string from UTF-8. It returns the converted string or
// "", err if any error occurred.
func (e *Encoder) String(s string) (string, error) {
s, _, err := transform.String(e, s)
if err != nil {
return "", err
}
return s, nil
}
// Writer wraps another Writer to encode its UTF-8 output.
//
// The Encoder may not be used for any other operation as long as the returned
// Writer is in use.
func (e *Encoder) Writer(w io.Writer) io.Writer {
return transform.NewWriter(w, e)
}
// ASCIISub is the ASCII substitute character, as recommended by
// http://unicode.org/reports/tr36/#Text_Comparison
const ASCIISub = '\x1a'
// Nop is the nop encoding. Its transformed bytes are the same as the source
// bytes; it does not replace invalid UTF-8 sequences.
var Nop Encoding = nop{}
type nop struct{}
func (nop) NewDecoder() *Decoder {
return &Decoder{Transformer: transform.Nop}
}
func (nop) NewEncoder() *Encoder {
return &Encoder{Transformer: transform.Nop}
}
// Replacement is the replacement encoding. Decoding from the replacement
// encoding yields a single '\uFFFD' replacement rune. Encoding from UTF-8 to
// the replacement encoding yields the same as the source bytes except that
// invalid UTF-8 is converted to '\uFFFD'.
//
// It is defined at http://encoding.spec.whatwg.org/#replacement
var Replacement Encoding = replacement{}
type replacement struct{}
func (replacement) NewDecoder() *Decoder {
return &Decoder{Transformer: replacementDecoder{}}
}
func (replacement) NewEncoder() *Encoder {
return &Encoder{Transformer: replacementEncoder{}}
}
func (replacement) ID() (mib identifier.MIB, other string) {
return identifier.Replacement, ""
}
type replacementDecoder struct{ transform.NopResetter }
func (replacementDecoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
if len(dst) < 3 {
return 0, 0, transform.ErrShortDst
}
if atEOF {
const fffd = "\ufffd"
dst[0] = fffd[0]
dst[1] = fffd[1]
dst[2] = fffd[2]
nDst = 3
}
return nDst, len(src), nil
}
type replacementEncoder struct{ transform.NopResetter }
func (replacementEncoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
r, size := rune(0), 0
for ; nSrc < len(src); nSrc += size {
r = rune(src[nSrc])
// Decode a 1-byte rune.
if r < utf8.RuneSelf {
size = 1
} else {
// Decode a multi-byte rune.
r, size = utf8.DecodeRune(src[nSrc:])
if size == 1 {
// All valid runes of size 1 (those below utf8.RuneSelf) were
// handled above. We have invalid UTF-8 or we haven't seen the
// full character yet.
if !atEOF && !utf8.FullRune(src[nSrc:]) {
err = transform.ErrShortSrc
break
}
r = '\ufffd'
}
}
if nDst+utf8.RuneLen(r) > len(dst) {
err = transform.ErrShortDst
break
}
nDst += utf8.EncodeRune(dst[nDst:], r)
}
return nDst, nSrc, err
}
// HTMLEscapeUnsupported wraps encoders to replace source runes outside the
// repertoire of the destination encoding with HTML escape sequences.
//
// This wrapper exists to comply to URL and HTML forms requiring a
// non-terminating legacy encoder. The produced sequences may lead to data
// loss as they are indistinguishable from legitimate input. To avoid this
// issue, use UTF-8 encodings whenever possible.
func HTMLEscapeUnsupported(e *Encoder) *Encoder {
return &Encoder{Transformer: &errorHandler{e, errorToHTML}}
}
// ReplaceUnsupported wraps encoders to replace source runes outside the
// repertoire of the destination encoding with an encoding-specific
// replacement.
//
// This wrapper is only provided for backwards compatibility and legacy
// handling. Its use is strongly discouraged. Use UTF-8 whenever possible.
func ReplaceUnsupported(e *Encoder) *Encoder {
return &Encoder{Transformer: &errorHandler{e, errorToReplacement}}
}
type errorHandler struct {
*Encoder
handler func(dst []byte, r rune, err repertoireError) (n int, ok bool)
}
// TODO: consider making this error public in some form.
type repertoireError interface {
Replacement() byte
}
func (h errorHandler) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
nDst, nSrc, err = h.Transformer.Transform(dst, src, atEOF)
for err != nil {
rerr, ok := err.(repertoireError)
if !ok {
return nDst, nSrc, err
}
r, sz := utf8.DecodeRune(src[nSrc:])
n, ok := h.handler(dst[nDst:], r, rerr)
if !ok {
return nDst, nSrc, transform.ErrShortDst
}
err = nil
nDst += n
if nSrc += sz; nSrc < len(src) {
var dn, sn int
dn, sn, err = h.Transformer.Transform(dst[nDst:], src[nSrc:], atEOF)
nDst += dn
nSrc += sn
}
}
return nDst, nSrc, err
}
func errorToHTML(dst []byte, r rune, err repertoireError) (n int, ok bool) {
buf := [8]byte{}
b := strconv.AppendUint(buf[:0], uint64(r), 10)
if n = len(b) + len("&#;"); n >= len(dst) {
return 0, false
}
dst[0] = '&'
dst[1] = '#'
dst[copy(dst[2:], b)+2] = ';'
return n, true
}
func errorToReplacement(dst []byte, r rune, err repertoireError) (n int, ok bool) {
if len(dst) == 0 {
return 0, false
}
dst[0] = err.Replacement()
return 1, true
}
// ErrInvalidUTF8 means that a transformer encountered invalid UTF-8.
var ErrInvalidUTF8 = errors.New("encoding: invalid UTF-8")
// UTF8Validator is a transformer that returns ErrInvalidUTF8 on the first
// input byte that is not valid UTF-8.
var UTF8Validator transform.Transformer = utf8Validator{}
type utf8Validator struct{ transform.NopResetter }
func (utf8Validator) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
n := len(src)
if n > len(dst) {
n = len(dst)
}
for i := 0; i < n; {
if c := src[i]; c < utf8.RuneSelf {
dst[i] = c
i++
continue
}
_, size := utf8.DecodeRune(src[i:])
if size == 1 {
// All valid runes of size 1 (those below utf8.RuneSelf) were
// handled above. We have invalid UTF-8 or we haven't seen the
// full character yet.
err = ErrInvalidUTF8
if !atEOF && !utf8.FullRune(src[i:]) {
err = transform.ErrShortSrc
}
return i, i, err
}
if i+size > len(dst) {
return i, i, transform.ErrShortDst
}
for ; size > 0; size-- {
dst[i] = src[i]
i++
}
}
if len(src) > len(dst) {
err = transform.ErrShortDst
}
return n, n, err
}

1128
vendor/golang.org/x/text/encoding/encoding_test.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

42
vendor/golang.org/x/text/encoding/example_test.go generated vendored Normal file
View File

@ -0,0 +1,42 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package encoding_test
import (
"fmt"
"io"
"os"
"strings"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/charmap"
"golang.org/x/text/encoding/unicode"
"golang.org/x/text/transform"
)
func ExampleDecodeWindows1252() {
sr := strings.NewReader("Gar\xe7on !")
tr := charmap.Windows1252.NewDecoder().Reader(sr)
io.Copy(os.Stdout, tr)
// Output: Garçon !
}
func ExampleUTF8Validator() {
for i := 0; i < 2; i++ {
var transformer transform.Transformer
transformer = unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM).NewEncoder()
if i == 1 {
transformer = transform.Chain(encoding.UTF8Validator, transformer)
}
dst := make([]byte, 256)
src := []byte("abc\xffxyz") // src is invalid UTF-8.
nDst, nSrc, err := transformer.Transform(dst, src, true)
fmt.Printf("i=%d: produced %q, consumed %q, error %v\n",
i, dst[:nDst], src[:nSrc], err)
}
// Output:
// i=0: produced "\x00a\x00b\x00c\xff\xfd\x00x\x00y\x00z", consumed "abc\xffxyz", error <nil>
// i=1: produced "\x00a\x00b\x00c", consumed "abc", error encoding: invalid UTF-8
}

167
vendor/golang.org/x/text/encoding/htmlindex/gen.go generated vendored Normal file
View File

@ -0,0 +1,167 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
package main
import (
"bytes"
"encoding/json"
"fmt"
"log"
"strings"
"golang.org/x/text/internal/gen"
)
type group struct {
Encodings []struct {
Labels []string
Name string
}
}
func main() {
gen.Init()
r := gen.Open("http://www.w3.org/TR", "w3", "encoding/indexes/encodings.json")
var groups []group
if err := json.NewDecoder(r).Decode(&groups); err != nil {
log.Fatalf("Error reading encodings.json: %v", err)
}
w := &bytes.Buffer{}
fmt.Fprintln(w, "type htmlEncoding byte")
fmt.Fprintln(w, "const (")
for i, g := range groups {
for _, e := range g.Encodings {
name := consts[e.Name]
if name == "" {
log.Fatalf("No const defined for %s.", e.Name)
}
if i == 0 {
fmt.Fprintf(w, "%s htmlEncoding = iota\n", name)
} else {
fmt.Fprintf(w, "%s\n", name)
}
}
}
fmt.Fprintln(w, "numEncodings")
fmt.Fprint(w, ")\n\n")
fmt.Fprintln(w, "var canonical = [numEncodings]string{")
for _, g := range groups {
for _, e := range g.Encodings {
fmt.Fprintf(w, "%q,\n", e.Name)
}
}
fmt.Fprint(w, "}\n\n")
fmt.Fprintln(w, "var nameMap = map[string]htmlEncoding{")
for _, g := range groups {
for _, e := range g.Encodings {
for _, l := range e.Labels {
fmt.Fprintf(w, "%q: %s,\n", l, consts[e.Name])
}
}
}
fmt.Fprint(w, "}\n\n")
var tags []string
fmt.Fprintln(w, "var localeMap = []htmlEncoding{")
for _, loc := range locales {
tags = append(tags, loc.tag)
fmt.Fprintf(w, "%s, // %s \n", consts[loc.name], loc.tag)
}
fmt.Fprint(w, "}\n\n")
fmt.Fprintf(w, "const locales = %q\n", strings.Join(tags, " "))
gen.WriteGoFile("tables.go", "htmlindex", w.Bytes())
}
// consts maps canonical encoding name to internal constant.
var consts = map[string]string{
"utf-8": "utf8",
"ibm866": "ibm866",
"iso-8859-2": "iso8859_2",
"iso-8859-3": "iso8859_3",
"iso-8859-4": "iso8859_4",
"iso-8859-5": "iso8859_5",
"iso-8859-6": "iso8859_6",
"iso-8859-7": "iso8859_7",
"iso-8859-8": "iso8859_8",
"iso-8859-8-i": "iso8859_8I",
"iso-8859-10": "iso8859_10",
"iso-8859-13": "iso8859_13",
"iso-8859-14": "iso8859_14",
"iso-8859-15": "iso8859_15",
"iso-8859-16": "iso8859_16",
"koi8-r": "koi8r",
"koi8-u": "koi8u",
"macintosh": "macintosh",
"windows-874": "windows874",
"windows-1250": "windows1250",
"windows-1251": "windows1251",
"windows-1252": "windows1252",
"windows-1253": "windows1253",
"windows-1254": "windows1254",
"windows-1255": "windows1255",
"windows-1256": "windows1256",
"windows-1257": "windows1257",
"windows-1258": "windows1258",
"x-mac-cyrillic": "macintoshCyrillic",
"gbk": "gbk",
"gb18030": "gb18030",
// "hz-gb-2312": "hzgb2312", // Was removed from WhatWG
"big5": "big5",
"euc-jp": "eucjp",
"iso-2022-jp": "iso2022jp",
"shift_jis": "shiftJIS",
"euc-kr": "euckr",
"replacement": "replacement",
"utf-16be": "utf16be",
"utf-16le": "utf16le",
"x-user-defined": "xUserDefined",
}
// locales is taken from
// https://html.spec.whatwg.org/multipage/syntax.html#encoding-sniffing-algorithm.
var locales = []struct{ tag, name string }{
{"und", "windows-1252"}, // The default value.
{"ar", "windows-1256"},
{"ba", "windows-1251"},
{"be", "windows-1251"},
{"bg", "windows-1251"},
{"cs", "windows-1250"},
{"el", "iso-8859-7"},
{"et", "windows-1257"},
{"fa", "windows-1256"},
{"he", "windows-1255"},
{"hr", "windows-1250"},
{"hu", "iso-8859-2"},
{"ja", "shift_jis"},
{"kk", "windows-1251"},
{"ko", "euc-kr"},
{"ku", "windows-1254"},
{"ky", "windows-1251"},
{"lt", "windows-1257"},
{"lv", "windows-1257"},
{"mk", "windows-1251"},
{"pl", "iso-8859-2"},
{"ru", "windows-1251"},
{"sah", "windows-1251"},
{"sk", "windows-1250"},
{"sl", "iso-8859-2"},
{"sr", "windows-1251"},
{"tg", "windows-1251"},
{"th", "windows-874"},
{"tr", "windows-1254"},
{"tt", "windows-1251"},
{"uk", "windows-1251"},
{"vi", "windows-1258"},
{"zh-hans", "gb18030"},
{"zh-hant", "big5"},
}

View File

@ -0,0 +1,86 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:generate go run gen.go
// Package htmlindex maps character set encoding names to Encodings as
// recommended by the W3C for use in HTML 5. See http://www.w3.org/TR/encoding.
package htmlindex
// TODO: perhaps have a "bare" version of the index (used by this package) that
// is not pre-loaded with all encodings. Global variables in encodings prevent
// the linker from being able to purge unneeded tables. This means that
// referencing all encodings, as this package does for the default index, links
// in all encodings unconditionally.
//
// This issue can be solved by either solving the linking issue (see
// https://github.com/golang/go/issues/6330) or refactoring the encoding tables
// (e.g. moving the tables to internal packages that do not use global
// variables).
// TODO: allow canonicalizing names
import (
"errors"
"strings"
"sync"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/internal/identifier"
"golang.org/x/text/language"
)
var (
errInvalidName = errors.New("htmlindex: invalid encoding name")
errUnknown = errors.New("htmlindex: unknown Encoding")
errUnsupported = errors.New("htmlindex: this encoding is not supported")
)
var (
matcherOnce sync.Once
matcher language.Matcher
)
// LanguageDefault returns the canonical name of the default encoding for a
// given language.
func LanguageDefault(tag language.Tag) string {
matcherOnce.Do(func() {
tags := []language.Tag{}
for _, t := range strings.Split(locales, " ") {
tags = append(tags, language.MustParse(t))
}
matcher = language.NewMatcher(tags)
})
_, i, _ := matcher.Match(tag)
return canonical[localeMap[i]] // Default is Windows-1252.
}
// Get returns an Encoding for one of the names listed in
// http://www.w3.org/TR/encoding using the Default Index. Matching is case-
// insensitive.
func Get(name string) (encoding.Encoding, error) {
x, ok := nameMap[strings.ToLower(strings.TrimSpace(name))]
if !ok {
return nil, errInvalidName
}
return encodings[x], nil
}
// Name reports the canonical name of the given Encoding. It will return
// an error if e is not associated with a supported encoding scheme.
func Name(e encoding.Encoding) (string, error) {
id, ok := e.(identifier.Interface)
if !ok {
return "", errUnknown
}
mib, _ := id.ID()
if mib == 0 {
return "", errUnknown
}
v, ok := mibMap[mib]
if !ok {
return "", errUnsupported
}
return canonical[v], nil
}

View File

@ -0,0 +1,144 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package htmlindex
import (
"testing"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/charmap"
"golang.org/x/text/encoding/internal/identifier"
"golang.org/x/text/encoding/unicode"
"golang.org/x/text/language"
)
func TestGet(t *testing.T) {
for i, tc := range []struct {
name string
canonical string
err error
}{
{"utf-8", "utf-8", nil},
{" utf-8 ", "utf-8", nil},
{" l5 ", "windows-1254", nil},
{"latin5 ", "windows-1254", nil},
{"latin 5", "", errInvalidName},
{"latin-5", "", errInvalidName},
} {
enc, err := Get(tc.name)
if err != tc.err {
t.Errorf("%d: error was %v; want %v", i, err, tc.err)
}
if err != nil {
continue
}
if got, err := Name(enc); got != tc.canonical {
t.Errorf("%d: Name(Get(%q)) = %q; want %q (%v)", i, tc.name, got, tc.canonical, err)
}
}
}
func TestTables(t *testing.T) {
for name, index := range nameMap {
got, err := Get(name)
if err != nil {
t.Errorf("%s:err: expected non-nil error", name)
}
if want := encodings[index]; got != want {
t.Errorf("%s:encoding: got %v; want %v", name, got, want)
}
mib, _ := got.(identifier.Interface).ID()
if mibMap[mib] != index {
t.Errorf("%s:mibMab: got %d; want %d", name, mibMap[mib], index)
}
}
}
func TestName(t *testing.T) {
for i, tc := range []struct {
desc string
enc encoding.Encoding
name string
err error
}{{
"defined encoding",
charmap.ISO8859_2,
"iso-8859-2",
nil,
}, {
"defined Unicode encoding",
unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM),
"utf-16be",
nil,
}, {
"undefined Unicode encoding in HTML standard",
unicode.UTF16(unicode.BigEndian, unicode.UseBOM),
"",
errUnsupported,
}, {
"undefined other encoding in HTML standard",
charmap.CodePage437,
"",
errUnsupported,
}, {
"unknown encoding",
encoding.Nop,
"",
errUnknown,
}} {
name, err := Name(tc.enc)
if name != tc.name || err != tc.err {
t.Errorf("%d:%s: got %q, %v; want %q, %v", i, tc.desc, name, err, tc.name, tc.err)
}
}
}
func TestLanguageDefault(t *testing.T) {
for _, tc := range []struct{ tag, want string }{
{"und", "windows-1252"}, // The default value.
{"ar", "windows-1256"},
{"ba", "windows-1251"},
{"be", "windows-1251"},
{"bg", "windows-1251"},
{"cs", "windows-1250"},
{"el", "iso-8859-7"},
{"et", "windows-1257"},
{"fa", "windows-1256"},
{"he", "windows-1255"},
{"hr", "windows-1250"},
{"hu", "iso-8859-2"},
{"ja", "shift_jis"},
{"kk", "windows-1251"},
{"ko", "euc-kr"},
{"ku", "windows-1254"},
{"ky", "windows-1251"},
{"lt", "windows-1257"},
{"lv", "windows-1257"},
{"mk", "windows-1251"},
{"pl", "iso-8859-2"},
{"ru", "windows-1251"},
{"sah", "windows-1251"},
{"sk", "windows-1250"},
{"sl", "iso-8859-2"},
{"sr", "windows-1251"},
{"tg", "windows-1251"},
{"th", "windows-874"},
{"tr", "windows-1254"},
{"tt", "windows-1251"},
{"uk", "windows-1251"},
{"vi", "windows-1258"},
{"zh-hans", "gb18030"},
{"zh-hant", "big5"},
// Variants and close approximates of the above.
{"ar_EG", "windows-1256"},
{"bs", "windows-1250"}, // Bosnian Latin maps to Croatian.
// Use default fallback in case of miss.
{"nl", "windows-1252"},
} {
if got := LanguageDefault(language.MustParse(tc.tag)); got != tc.want {
t.Errorf("LanguageDefault(%s) = %s; want %s", tc.tag, got, tc.want)
}
}
}

105
vendor/golang.org/x/text/encoding/htmlindex/map.go generated vendored Normal file
View File

@ -0,0 +1,105 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package htmlindex
import (
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/charmap"
"golang.org/x/text/encoding/internal/identifier"
"golang.org/x/text/encoding/japanese"
"golang.org/x/text/encoding/korean"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/encoding/traditionalchinese"
"golang.org/x/text/encoding/unicode"
)
// mibMap maps a MIB identifier to an htmlEncoding index.
var mibMap = map[identifier.MIB]htmlEncoding{
identifier.UTF8: utf8,
identifier.UTF16BE: utf16be,
identifier.UTF16LE: utf16le,
identifier.IBM866: ibm866,
identifier.ISOLatin2: iso8859_2,
identifier.ISOLatin3: iso8859_3,
identifier.ISOLatin4: iso8859_4,
identifier.ISOLatinCyrillic: iso8859_5,
identifier.ISOLatinArabic: iso8859_6,
identifier.ISOLatinGreek: iso8859_7,
identifier.ISOLatinHebrew: iso8859_8,
identifier.ISO88598I: iso8859_8I,
identifier.ISOLatin6: iso8859_10,
identifier.ISO885913: iso8859_13,
identifier.ISO885914: iso8859_14,
identifier.ISO885915: iso8859_15,
identifier.ISO885916: iso8859_16,
identifier.KOI8R: koi8r,
identifier.KOI8U: koi8u,
identifier.Macintosh: macintosh,
identifier.MacintoshCyrillic: macintoshCyrillic,
identifier.Windows874: windows874,
identifier.Windows1250: windows1250,
identifier.Windows1251: windows1251,
identifier.Windows1252: windows1252,
identifier.Windows1253: windows1253,
identifier.Windows1254: windows1254,
identifier.Windows1255: windows1255,
identifier.Windows1256: windows1256,
identifier.Windows1257: windows1257,
identifier.Windows1258: windows1258,
identifier.XUserDefined: xUserDefined,
identifier.GBK: gbk,
identifier.GB18030: gb18030,
identifier.Big5: big5,
identifier.EUCPkdFmtJapanese: eucjp,
identifier.ISO2022JP: iso2022jp,
identifier.ShiftJIS: shiftJIS,
identifier.EUCKR: euckr,
identifier.Replacement: replacement,
}
// encodings maps the internal htmlEncoding to an Encoding.
// TODO: consider using a reusable index in encoding/internal.
var encodings = [numEncodings]encoding.Encoding{
utf8: unicode.UTF8,
ibm866: charmap.CodePage866,
iso8859_2: charmap.ISO8859_2,
iso8859_3: charmap.ISO8859_3,
iso8859_4: charmap.ISO8859_4,
iso8859_5: charmap.ISO8859_5,
iso8859_6: charmap.ISO8859_6,
iso8859_7: charmap.ISO8859_7,
iso8859_8: charmap.ISO8859_8,
iso8859_8I: charmap.ISO8859_8I,
iso8859_10: charmap.ISO8859_10,
iso8859_13: charmap.ISO8859_13,
iso8859_14: charmap.ISO8859_14,
iso8859_15: charmap.ISO8859_15,
iso8859_16: charmap.ISO8859_16,
koi8r: charmap.KOI8R,
koi8u: charmap.KOI8U,
macintosh: charmap.Macintosh,
windows874: charmap.Windows874,
windows1250: charmap.Windows1250,
windows1251: charmap.Windows1251,
windows1252: charmap.Windows1252,
windows1253: charmap.Windows1253,
windows1254: charmap.Windows1254,
windows1255: charmap.Windows1255,
windows1256: charmap.Windows1256,
windows1257: charmap.Windows1257,
windows1258: charmap.Windows1258,
macintoshCyrillic: charmap.MacintoshCyrillic,
gbk: simplifiedchinese.GBK,
gb18030: simplifiedchinese.GB18030,
big5: traditionalchinese.Big5,
eucjp: japanese.EUCJP,
iso2022jp: japanese.ISO2022JP,
shiftJIS: japanese.ShiftJIS,
euckr: korean.EUCKR,
replacement: encoding.Replacement,
utf16be: unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM),
utf16le: unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM),
xUserDefined: charmap.XUserDefined,
}

352
vendor/golang.org/x/text/encoding/htmlindex/tables.go generated vendored Normal file
View File

@ -0,0 +1,352 @@
// This file was generated by go generate; DO NOT EDIT
package htmlindex
type htmlEncoding byte
const (
utf8 htmlEncoding = iota
ibm866
iso8859_2
iso8859_3
iso8859_4
iso8859_5
iso8859_6
iso8859_7
iso8859_8
iso8859_8I
iso8859_10
iso8859_13
iso8859_14
iso8859_15
iso8859_16
koi8r
koi8u
macintosh
windows874
windows1250
windows1251
windows1252
windows1253
windows1254
windows1255
windows1256
windows1257
windows1258
macintoshCyrillic
gbk
gb18030
big5
eucjp
iso2022jp
shiftJIS
euckr
replacement
utf16be
utf16le
xUserDefined
numEncodings
)
var canonical = [numEncodings]string{
"utf-8",
"ibm866",
"iso-8859-2",
"iso-8859-3",
"iso-8859-4",
"iso-8859-5",
"iso-8859-6",
"iso-8859-7",
"iso-8859-8",
"iso-8859-8-i",
"iso-8859-10",
"iso-8859-13",
"iso-8859-14",
"iso-8859-15",
"iso-8859-16",
"koi8-r",
"koi8-u",
"macintosh",
"windows-874",
"windows-1250",
"windows-1251",
"windows-1252",
"windows-1253",
"windows-1254",
"windows-1255",
"windows-1256",
"windows-1257",
"windows-1258",
"x-mac-cyrillic",
"gbk",
"gb18030",
"big5",
"euc-jp",
"iso-2022-jp",
"shift_jis",
"euc-kr",
"replacement",
"utf-16be",
"utf-16le",
"x-user-defined",
}
var nameMap = map[string]htmlEncoding{
"unicode-1-1-utf-8": utf8,
"utf-8": utf8,
"utf8": utf8,
"866": ibm866,
"cp866": ibm866,
"csibm866": ibm866,
"ibm866": ibm866,
"csisolatin2": iso8859_2,
"iso-8859-2": iso8859_2,
"iso-ir-101": iso8859_2,
"iso8859-2": iso8859_2,
"iso88592": iso8859_2,
"iso_8859-2": iso8859_2,
"iso_8859-2:1987": iso8859_2,
"l2": iso8859_2,
"latin2": iso8859_2,
"csisolatin3": iso8859_3,
"iso-8859-3": iso8859_3,
"iso-ir-109": iso8859_3,
"iso8859-3": iso8859_3,
"iso88593": iso8859_3,
"iso_8859-3": iso8859_3,
"iso_8859-3:1988": iso8859_3,
"l3": iso8859_3,
"latin3": iso8859_3,
"csisolatin4": iso8859_4,
"iso-8859-4": iso8859_4,
"iso-ir-110": iso8859_4,
"iso8859-4": iso8859_4,
"iso88594": iso8859_4,
"iso_8859-4": iso8859_4,
"iso_8859-4:1988": iso8859_4,
"l4": iso8859_4,
"latin4": iso8859_4,
"csisolatincyrillic": iso8859_5,
"cyrillic": iso8859_5,
"iso-8859-5": iso8859_5,
"iso-ir-144": iso8859_5,
"iso8859-5": iso8859_5,
"iso88595": iso8859_5,
"iso_8859-5": iso8859_5,
"iso_8859-5:1988": iso8859_5,
"arabic": iso8859_6,
"asmo-708": iso8859_6,
"csiso88596e": iso8859_6,
"csiso88596i": iso8859_6,
"csisolatinarabic": iso8859_6,
"ecma-114": iso8859_6,
"iso-8859-6": iso8859_6,
"iso-8859-6-e": iso8859_6,
"iso-8859-6-i": iso8859_6,
"iso-ir-127": iso8859_6,
"iso8859-6": iso8859_6,
"iso88596": iso8859_6,
"iso_8859-6": iso8859_6,
"iso_8859-6:1987": iso8859_6,
"csisolatingreek": iso8859_7,
"ecma-118": iso8859_7,
"elot_928": iso8859_7,
"greek": iso8859_7,
"greek8": iso8859_7,
"iso-8859-7": iso8859_7,
"iso-ir-126": iso8859_7,
"iso8859-7": iso8859_7,
"iso88597": iso8859_7,
"iso_8859-7": iso8859_7,
"iso_8859-7:1987": iso8859_7,
"sun_eu_greek": iso8859_7,
"csiso88598e": iso8859_8,
"csisolatinhebrew": iso8859_8,
"hebrew": iso8859_8,
"iso-8859-8": iso8859_8,
"iso-8859-8-e": iso8859_8,
"iso-ir-138": iso8859_8,
"iso8859-8": iso8859_8,
"iso88598": iso8859_8,
"iso_8859-8": iso8859_8,
"iso_8859-8:1988": iso8859_8,
"visual": iso8859_8,
"csiso88598i": iso8859_8I,
"iso-8859-8-i": iso8859_8I,
"logical": iso8859_8I,
"csisolatin6": iso8859_10,
"iso-8859-10": iso8859_10,
"iso-ir-157": iso8859_10,
"iso8859-10": iso8859_10,
"iso885910": iso8859_10,
"l6": iso8859_10,
"latin6": iso8859_10,
"iso-8859-13": iso8859_13,
"iso8859-13": iso8859_13,
"iso885913": iso8859_13,
"iso-8859-14": iso8859_14,
"iso8859-14": iso8859_14,
"iso885914": iso8859_14,
"csisolatin9": iso8859_15,
"iso-8859-15": iso8859_15,
"iso8859-15": iso8859_15,
"iso885915": iso8859_15,
"iso_8859-15": iso8859_15,
"l9": iso8859_15,
"iso-8859-16": iso8859_16,
"cskoi8r": koi8r,
"koi": koi8r,
"koi8": koi8r,
"koi8-r": koi8r,
"koi8_r": koi8r,
"koi8-ru": koi8u,
"koi8-u": koi8u,
"csmacintosh": macintosh,
"mac": macintosh,
"macintosh": macintosh,
"x-mac-roman": macintosh,
"dos-874": windows874,
"iso-8859-11": windows874,
"iso8859-11": windows874,
"iso885911": windows874,
"tis-620": windows874,
"windows-874": windows874,
"cp1250": windows1250,
"windows-1250": windows1250,
"x-cp1250": windows1250,
"cp1251": windows1251,
"windows-1251": windows1251,
"x-cp1251": windows1251,
"ansi_x3.4-1968": windows1252,
"ascii": windows1252,
"cp1252": windows1252,
"cp819": windows1252,
"csisolatin1": windows1252,
"ibm819": windows1252,
"iso-8859-1": windows1252,
"iso-ir-100": windows1252,
"iso8859-1": windows1252,
"iso88591": windows1252,
"iso_8859-1": windows1252,
"iso_8859-1:1987": windows1252,
"l1": windows1252,
"latin1": windows1252,
"us-ascii": windows1252,
"windows-1252": windows1252,
"x-cp1252": windows1252,
"cp1253": windows1253,
"windows-1253": windows1253,
"x-cp1253": windows1253,
"cp1254": windows1254,
"csisolatin5": windows1254,
"iso-8859-9": windows1254,
"iso-ir-148": windows1254,
"iso8859-9": windows1254,
"iso88599": windows1254,
"iso_8859-9": windows1254,
"iso_8859-9:1989": windows1254,
"l5": windows1254,
"latin5": windows1254,
"windows-1254": windows1254,
"x-cp1254": windows1254,
"cp1255": windows1255,
"windows-1255": windows1255,
"x-cp1255": windows1255,
"cp1256": windows1256,
"windows-1256": windows1256,
"x-cp1256": windows1256,
"cp1257": windows1257,
"windows-1257": windows1257,
"x-cp1257": windows1257,
"cp1258": windows1258,
"windows-1258": windows1258,
"x-cp1258": windows1258,
"x-mac-cyrillic": macintoshCyrillic,
"x-mac-ukrainian": macintoshCyrillic,
"chinese": gbk,
"csgb2312": gbk,
"csiso58gb231280": gbk,
"gb2312": gbk,
"gb_2312": gbk,
"gb_2312-80": gbk,
"gbk": gbk,
"iso-ir-58": gbk,
"x-gbk": gbk,
"gb18030": gb18030,
"big5": big5,
"big5-hkscs": big5,
"cn-big5": big5,
"csbig5": big5,
"x-x-big5": big5,
"cseucpkdfmtjapanese": eucjp,
"euc-jp": eucjp,
"x-euc-jp": eucjp,
"csiso2022jp": iso2022jp,
"iso-2022-jp": iso2022jp,
"csshiftjis": shiftJIS,
"ms932": shiftJIS,
"ms_kanji": shiftJIS,
"shift-jis": shiftJIS,
"shift_jis": shiftJIS,
"sjis": shiftJIS,
"windows-31j": shiftJIS,
"x-sjis": shiftJIS,
"cseuckr": euckr,
"csksc56011987": euckr,
"euc-kr": euckr,
"iso-ir-149": euckr,
"korean": euckr,
"ks_c_5601-1987": euckr,
"ks_c_5601-1989": euckr,
"ksc5601": euckr,
"ksc_5601": euckr,
"windows-949": euckr,
"csiso2022kr": replacement,
"hz-gb-2312": replacement,
"iso-2022-cn": replacement,
"iso-2022-cn-ext": replacement,
"iso-2022-kr": replacement,
"utf-16be": utf16be,
"utf-16": utf16le,
"utf-16le": utf16le,
"x-user-defined": xUserDefined,
}
var localeMap = []htmlEncoding{
windows1252, // und
windows1256, // ar
windows1251, // ba
windows1251, // be
windows1251, // bg
windows1250, // cs
iso8859_7, // el
windows1257, // et
windows1256, // fa
windows1255, // he
windows1250, // hr
iso8859_2, // hu
shiftJIS, // ja
windows1251, // kk
euckr, // ko
windows1254, // ku
windows1251, // ky
windows1257, // lt
windows1257, // lv
windows1251, // mk
iso8859_2, // pl
windows1251, // ru
windows1251, // sah
windows1250, // sk
iso8859_2, // sl
windows1251, // sr
windows1251, // tg
windows874, // th
windows1254, // tr
windows1251, // tt
windows1251, // uk
windows1258, // vi
gb18030, // zh-hans
big5, // zh-hant
}
const locales = "und ar ba be bg cs el et fa he hr hu ja kk ko ku ky lt lv mk pl ru sah sk sl sr tg th tr tt uk vi zh-hans zh-hant"

View File

@ -0,0 +1,26 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ianaindex_test
import (
"fmt"
"golang.org/x/text/encoding/charmap"
"golang.org/x/text/encoding/ianaindex"
)
func ExampleIndex() {
fmt.Println(ianaindex.MIME.Name(charmap.ISO8859_7))
fmt.Println(ianaindex.IANA.Name(charmap.ISO8859_7))
e, _ := ianaindex.IANA.Get("cp437")
fmt.Println(ianaindex.IANA.Name(e))
// TODO: Output:
// ISO-8859-7
// ISO8859_7:1987
// IBM437
}

View File

@ -0,0 +1,64 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package ianaindex maps names to Encodings as specified by the IANA registry.
// This includes both the MIME and IANA names.
//
// See http://www.iana.org/assignments/character-sets/character-sets.xhtml for
// more details.
package ianaindex
import (
"golang.org/x/text/encoding"
)
// TODO: allow users to specify their own aliases?
// TODO: allow users to specify their own indexes?
// TODO: allow canonicalizing names
// NOTE: only use these top-level variables if we can get the linker to drop
// the indexes when they are not used. Make them a function or perhaps only
// support MIME otherwise.
var (
// MIME is an index to map MIME names. It does not support aliases.
MIME *Index
// IANA is an index that supports all names and aliases using IANA names as
// the canonical identifier.
IANA *Index
)
// Index maps names registered by IANA to Encodings.
type Index struct {
}
// Get returns an Encoding for IANA-registered names. Matching is
// case-insensitive.
func (x *Index) Get(name string) (encoding.Encoding, error) {
panic("TODO: implement")
}
// Name reports the canonical name of the given Encoding. It will return an
// error if the e is not associated with a known encoding scheme.
func (x *Index) Name(e encoding.Encoding) (string, error) {
panic("TODO: implement")
}
// TODO: the coverage of this index is rather spotty. Allowing users to set
// encodings would allow:
// - users to increase coverage
// - allow a partially loaded set of encodings in case the user doesn't need to
// them all.
// - write an OS-specific wrapper for supported encodings and set them.
// The exact definition of Set depends a bit on if and how we want to let users
// write their own Encoding implementations. Also, it is not possible yet to
// only partially load the encodings without doing some refactoring. Until this
// is solved, we might as well not support Set.
// // Set sets the e to be used for the encoding scheme identified by name. Only
// // canonical names may be used. An empty name assigns e to its internally
// // associated encoding scheme.
// func (x *Index) Set(name string, e encoding.Encoding) error {
// panic("TODO: implement")
// }

View File

@ -0,0 +1,137 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
package main
import (
"bytes"
"encoding/xml"
"fmt"
"io"
"log"
"strings"
"golang.org/x/text/internal/gen"
)
type registry struct {
XMLName xml.Name `xml:"registry"`
Updated string `xml:"updated"`
Registry []struct {
ID string `xml:"id,attr"`
Record []struct {
Name string `xml:"name"`
Xref []struct {
Type string `xml:"type,attr"`
Data string `xml:"data,attr"`
} `xml:"xref"`
Desc struct {
Data string `xml:",innerxml"`
// Any []struct {
// Data string `xml:",chardata"`
// } `xml:",any"`
// Data string `xml:",chardata"`
} `xml:"description,"`
MIB string `xml:"value"`
Alias []string `xml:"alias"`
MIME string `xml:"preferred_alias"`
} `xml:"record"`
} `xml:"registry"`
}
func main() {
r := gen.OpenIANAFile("assignments/character-sets/character-sets.xml")
reg := &registry{}
if err := xml.NewDecoder(r).Decode(&reg); err != nil && err != io.EOF {
log.Fatalf("Error decoding charset registry: %v", err)
}
if len(reg.Registry) == 0 || reg.Registry[0].ID != "character-sets-1" {
log.Fatalf("Unexpected ID %s", reg.Registry[0].ID)
}
w := &bytes.Buffer{}
fmt.Fprintf(w, "const (\n")
for _, rec := range reg.Registry[0].Record {
constName := ""
for _, a := range rec.Alias {
if strings.HasPrefix(a, "cs") && strings.IndexByte(a, '-') == -1 {
// Some of the constant definitions have comments in them. Strip those.
constName = strings.Title(strings.SplitN(a[2:], "\n", 2)[0])
}
}
if constName == "" {
switch rec.MIB {
case "2085":
constName = "HZGB2312" // Not listed as alias for some reason.
default:
log.Fatalf("No cs alias defined for %s.", rec.MIB)
}
}
if rec.MIME != "" {
rec.MIME = fmt.Sprintf(" (MIME: %s)", rec.MIME)
}
fmt.Fprintf(w, "// %s is the MIB identifier with IANA name %s%s.\n//\n", constName, rec.Name, rec.MIME)
if len(rec.Desc.Data) > 0 {
fmt.Fprint(w, "// ")
d := xml.NewDecoder(strings.NewReader(rec.Desc.Data))
inElem := true
attr := ""
for {
t, err := d.Token()
if err != nil {
if err != io.EOF {
log.Fatal(err)
}
break
}
switch x := t.(type) {
case xml.CharData:
attr = "" // Don't need attribute info.
a := bytes.Split([]byte(x), []byte("\n"))
for i, b := range a {
if b = bytes.TrimSpace(b); len(b) != 0 {
if !inElem && i > 0 {
fmt.Fprint(w, "\n// ")
}
inElem = false
fmt.Fprintf(w, "%s ", string(b))
}
}
case xml.StartElement:
if x.Name.Local == "xref" {
inElem = true
use := false
for _, a := range x.Attr {
if a.Name.Local == "type" {
use = use || a.Value != "person"
}
if a.Name.Local == "data" && use {
attr = a.Value + " "
}
}
}
case xml.EndElement:
inElem = false
fmt.Fprint(w, attr)
}
}
fmt.Fprint(w, "\n")
}
for _, x := range rec.Xref {
switch x.Type {
case "rfc":
fmt.Fprintf(w, "// Reference: %s\n", strings.ToUpper(x.Data))
case "uri":
fmt.Fprintf(w, "// Reference: %s\n", x.Data)
}
}
fmt.Fprintf(w, "%s MIB = %s\n", constName, rec.MIB)
fmt.Fprintln(w)
}
fmt.Fprintln(w, ")")
gen.WriteGoFile("mib.go", "identifier", w.Bytes())
}

View File

@ -0,0 +1,81 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:generate go run gen.go
// Package identifier defines the contract between implementations of Encoding
// and Index by defining identifiers that uniquely identify standardized coded
// character sets (CCS) and character encoding schemes (CES), which we will
// together refer to as encodings, for which Encoding implementations provide
// converters to and from UTF-8. This package is typically only of concern to
// implementers of Indexes and Encodings.
//
// One part of the identifier is the MIB code, which is defined by IANA and
// uniquely identifies a CCS or CES. Each code is associated with data that
// references authorities, official documentation as well as aliases and MIME
// names.
//
// Not all CESs are covered by the IANA registry. The "other" string that is
// returned by ID can be used to identify other character sets or versions of
// existing ones.
//
// It is recommended that each package that provides a set of Encodings provide
// the All and Common variables to reference all supported encodings and
// commonly used subset. This allows Index implementations to include all
// available encodings without explicitly referencing or knowing about them.
package identifier
// Note: this package is internal, but could be made public if there is a need
// for writing third-party Indexes and Encodings.
// References:
// - http://source.icu-project.org/repos/icu/icu/trunk/source/data/mappings/convrtrs.txt
// - http://www.iana.org/assignments/character-sets/character-sets.xhtml
// - http://www.iana.org/assignments/ianacharset-mib/ianacharset-mib
// - http://www.ietf.org/rfc/rfc2978.txt
// - http://www.unicode.org/reports/tr22/
// - http://www.w3.org/TR/encoding/
// - http://www.w3.org/TR/encoding/indexes/encodings.json
// - https://encoding.spec.whatwg.org/
// - https://tools.ietf.org/html/rfc6657#section-5
// Interface can be implemented by Encodings to define the CCS or CES for which
// it implements conversions.
type Interface interface {
// ID returns an encoding identifier. Exactly one of the mib and other
// values should be non-zero.
//
// In the usual case it is only necessary to indicate the MIB code. The
// other string can be used to specify encodings for which there is no MIB,
// such as "x-mac-dingbat".
//
// The other string may only contain the characters a-z, A-Z, 0-9, - and _.
ID() (mib MIB, other string)
// NOTE: the restrictions on the encoding are to allow extending the syntax
// with additional information such as versions, vendors and other variants.
}
// A MIB identifies an encoding. It is derived from the IANA MIB codes and adds
// some identifiers for some encodings that are not covered by the IANA
// standard.
//
// See http://www.iana.org/assignments/ianacharset-mib.
type MIB uint16
// These additional MIB types are not defined in IANA. They are added because
// they are common and defined within the text repo.
const (
// Unofficial marks the start of encodings not registered by IANA.
Unofficial MIB = 10000 + iota
// Replacement is the WhatWG replacement encoding.
Replacement
// XUserDefined is the code for x-user-defined.
XUserDefined
// MacintoshCyrillic is the code for x-mac-cyrillic.
MacintoshCyrillic
)

File diff suppressed because it is too large Load Diff

75
vendor/golang.org/x/text/encoding/internal/internal.go generated vendored Normal file
View File

@ -0,0 +1,75 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package internal contains code that is shared among encoding implementations.
package internal
import (
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/internal/identifier"
"golang.org/x/text/transform"
)
// Encoding is an implementation of the Encoding interface that adds the String
// and ID methods to an existing encoding.
type Encoding struct {
encoding.Encoding
Name string
MIB identifier.MIB
}
// _ verifies that Encoding implements identifier.Interface.
var _ identifier.Interface = (*Encoding)(nil)
func (e *Encoding) String() string {
return e.Name
}
func (e *Encoding) ID() (mib identifier.MIB, other string) {
return e.MIB, ""
}
// SimpleEncoding is an Encoding that combines two Transformers.
type SimpleEncoding struct {
Decoder transform.Transformer
Encoder transform.Transformer
}
func (e *SimpleEncoding) NewDecoder() *encoding.Decoder {
return &encoding.Decoder{Transformer: e.Decoder}
}
func (e *SimpleEncoding) NewEncoder() *encoding.Encoder {
return &encoding.Encoder{Transformer: e.Encoder}
}
// FuncEncoding is an Encoding that combines two functions returning a new
// Transformer.
type FuncEncoding struct {
Decoder func() transform.Transformer
Encoder func() transform.Transformer
}
func (e FuncEncoding) NewDecoder() *encoding.Decoder {
return &encoding.Decoder{Transformer: e.Decoder()}
}
func (e FuncEncoding) NewEncoder() *encoding.Encoder {
return &encoding.Encoder{Transformer: e.Encoder()}
}
// A RepertoireError indicates a rune is not in the repertoire of a destination
// encoding. It is associated with an encoding-specific suggested replacement
// byte.
type RepertoireError byte
// Error implements the error interrface.
func (r RepertoireError) Error() string {
return "encoding: rune not supported by encoding."
}
// Replacement returns the replacement string associated with this error.
func (r RepertoireError) Replacement() byte { return byte(r) }
var ErrASCIIReplacement = RepertoireError(encoding.ASCIISub)

12
vendor/golang.org/x/text/encoding/japanese/all.go generated vendored Normal file
View File

@ -0,0 +1,12 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package japanese
import (
"golang.org/x/text/encoding"
)
// All is a list of all defined encodings in this package.
var All = []encoding.Encoding{EUCJP, ISO2022JP, ShiftJIS}

80
vendor/golang.org/x/text/encoding/japanese/all_test.go generated vendored Normal file
View File

@ -0,0 +1,80 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package japanese
import (
"testing"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/internal"
"golang.org/x/text/transform"
)
func dec(e encoding.Encoding) (dir string, t transform.Transformer, err error) {
return "Decode", e.NewDecoder(), nil
}
func enc(e encoding.Encoding) (dir string, t transform.Transformer, err error) {
return "Encode", e.NewEncoder(), internal.ErrASCIIReplacement
}
func TestNonRepertoire(t *testing.T) {
testCases := []struct {
init func(e encoding.Encoding) (string, transform.Transformer, error)
e encoding.Encoding
src, want string
}{
{dec, EUCJP, "\xfe\xfc", "\ufffd"},
{dec, ISO2022JP, "\x1b$B\x7e\x7e", "\ufffd"},
{dec, ShiftJIS, "\xef\xfc", "\ufffd"},
{enc, EUCJP, "갂", ""},
{enc, EUCJP, "a갂", "a"},
{enc, EUCJP, "丌갂", "\x8f\xb0\xa4"},
{enc, ISO2022JP, "갂", ""},
{enc, ISO2022JP, "a갂", "a"},
{enc, ISO2022JP, "朗갂", "\x1b$BzF\x1b(B"}, // switch back to ASCII mode at end
{enc, ShiftJIS, "갂", ""},
{enc, ShiftJIS, "a갂", "a"},
{enc, ShiftJIS, "\u2190갂", "\x81\xa9"},
}
for _, tc := range testCases {
dir, tr, wantErr := tc.init(tc.e)
dst, _, err := transform.String(tr, tc.src)
if err != wantErr {
t.Errorf("%s %v(%q): got %v; want %v", dir, tc.e, tc.src, err, wantErr)
}
if got := string(dst); got != tc.want {
t.Errorf("%s %v(%q):\ngot %q\nwant %q", dir, tc.e, tc.src, got, tc.want)
}
}
}
func TestCorrect(t *testing.T) {
testCases := []struct {
init func(e encoding.Encoding) (string, transform.Transformer, error)
e encoding.Encoding
src, want string
}{
{dec, ShiftJIS, "\x9f\xfc", "滌"},
{dec, ShiftJIS, "\xfb\xfc", "髙"},
{dec, ShiftJIS, "\xfa\xb1", "﨑"},
{enc, ShiftJIS, "滌", "\x9f\xfc"},
{enc, ShiftJIS, "﨑", "\xed\x95"},
}
for _, tc := range testCases {
dir, tr, _ := tc.init(tc.e)
dst, _, err := transform.String(tr, tc.src)
if err != nil {
t.Errorf("%s %v(%q): got %v; want %v", dir, tc.e, tc.src, err, nil)
}
if got := string(dst); got != tc.want {
t.Errorf("%s %v(%q):\ngot %q\nwant %q", dir, tc.e, tc.src, got, tc.want)
}
}
}

211
vendor/golang.org/x/text/encoding/japanese/eucjp.go generated vendored Normal file
View File

@ -0,0 +1,211 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package japanese
import (
"errors"
"unicode/utf8"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/internal"
"golang.org/x/text/encoding/internal/identifier"
"golang.org/x/text/transform"
)
// EUCJP is the EUC-JP encoding.
var EUCJP encoding.Encoding = &eucJP
var eucJP = internal.Encoding{
&internal.SimpleEncoding{eucJPDecoder{}, eucJPEncoder{}},
"EUC-JP",
identifier.EUCPkdFmtJapanese,
}
var errInvalidEUCJP = errors.New("japanese: invalid EUC-JP encoding")
type eucJPDecoder struct{ transform.NopResetter }
func (eucJPDecoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
r, size := rune(0), 0
loop:
for ; nSrc < len(src); nSrc += size {
switch c0 := src[nSrc]; {
case c0 < utf8.RuneSelf:
r, size = rune(c0), 1
case c0 == 0x8e:
if nSrc+1 >= len(src) {
err = transform.ErrShortSrc
break loop
}
c1 := src[nSrc+1]
if c1 < 0xa1 || 0xdf < c1 {
err = errInvalidEUCJP
break loop
}
r, size = rune(c1)+(0xff61-0xa1), 2
case c0 == 0x8f:
if nSrc+2 >= len(src) {
err = transform.ErrShortSrc
break loop
}
c1 := src[nSrc+1]
if c1 < 0xa1 || 0xfe < c1 {
err = errInvalidEUCJP
break loop
}
c2 := src[nSrc+2]
if c2 < 0xa1 || 0xfe < c2 {
err = errInvalidEUCJP
break loop
}
r, size = '\ufffd', 3
if i := int(c1-0xa1)*94 + int(c2-0xa1); i < len(jis0212Decode) {
r = rune(jis0212Decode[i])
if r == 0 {
r = '\ufffd'
}
}
case 0xa1 <= c0 && c0 <= 0xfe:
if nSrc+1 >= len(src) {
err = transform.ErrShortSrc
break loop
}
c1 := src[nSrc+1]
if c1 < 0xa1 || 0xfe < c1 {
err = errInvalidEUCJP
break loop
}
r, size = '\ufffd', 2
if i := int(c0-0xa1)*94 + int(c1-0xa1); i < len(jis0208Decode) {
r = rune(jis0208Decode[i])
if r == 0 {
r = '\ufffd'
}
}
default:
err = errInvalidEUCJP
break loop
}
if nDst+utf8.RuneLen(r) > len(dst) {
err = transform.ErrShortDst
break loop
}
nDst += utf8.EncodeRune(dst[nDst:], r)
}
if atEOF && err == transform.ErrShortSrc {
err = errInvalidEUCJP
}
return nDst, nSrc, err
}
type eucJPEncoder struct{ transform.NopResetter }
func (eucJPEncoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
r, size := rune(0), 0
for ; nSrc < len(src); nSrc += size {
r = rune(src[nSrc])
// Decode a 1-byte rune.
if r < utf8.RuneSelf {
size = 1
} else {
// Decode a multi-byte rune.
r, size = utf8.DecodeRune(src[nSrc:])
if size == 1 {
// All valid runes of size 1 (those below utf8.RuneSelf) were
// handled above. We have invalid UTF-8 or we haven't seen the
// full character yet.
if !atEOF && !utf8.FullRune(src[nSrc:]) {
err = transform.ErrShortSrc
break
}
}
// func init checks that the switch covers all tables.
switch {
case encode0Low <= r && r < encode0High:
if r = rune(encode0[r-encode0Low]); r != 0 {
goto write2or3
}
case encode1Low <= r && r < encode1High:
if r = rune(encode1[r-encode1Low]); r != 0 {
goto write2or3
}
case encode2Low <= r && r < encode2High:
if r = rune(encode2[r-encode2Low]); r != 0 {
goto write2or3
}
case encode3Low <= r && r < encode3High:
if r = rune(encode3[r-encode3Low]); r != 0 {
goto write2or3
}
case encode4Low <= r && r < encode4High:
if r = rune(encode4[r-encode4Low]); r != 0 {
goto write2or3
}
case encode5Low <= r && r < encode5High:
if 0xff61 <= r && r < 0xffa0 {
goto write2
}
if r = rune(encode5[r-encode5Low]); r != 0 {
goto write2or3
}
}
err = internal.ErrASCIIReplacement
break
}
if nDst >= len(dst) {
err = transform.ErrShortDst
break
}
dst[nDst] = uint8(r)
nDst++
continue
write2or3:
if r>>tableShift == jis0208 {
if nDst+2 > len(dst) {
err = transform.ErrShortDst
break
}
} else {
if nDst+3 > len(dst) {
err = transform.ErrShortDst
break
}
dst[nDst] = 0x8f
nDst++
}
dst[nDst+0] = 0xa1 + uint8(r>>codeShift)&codeMask
dst[nDst+1] = 0xa1 + uint8(r)&codeMask
nDst += 2
continue
write2:
if nDst+2 > len(dst) {
err = transform.ErrShortDst
break
}
dst[nDst+0] = 0x8e
dst[nDst+1] = uint8(r - (0xff61 - 0xa1))
nDst += 2
continue
}
return nDst, nSrc, err
}
func init() {
// Check that the hard-coded encode switch covers all tables.
if numEncodeTables != 6 {
panic("bad numEncodeTables")
}
}

296
vendor/golang.org/x/text/encoding/japanese/iso2022jp.go generated vendored Normal file
View File

@ -0,0 +1,296 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package japanese
import (
"errors"
"unicode/utf8"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/internal"
"golang.org/x/text/encoding/internal/identifier"
"golang.org/x/text/transform"
)
// ISO2022JP is the ISO-2022-JP encoding.
var ISO2022JP encoding.Encoding = &iso2022JP
var iso2022JP = internal.Encoding{
internal.FuncEncoding{iso2022JPNewDecoder, iso2022JPNewEncoder},
"ISO-2022-JP",
identifier.ISO2022JP,
}
func iso2022JPNewDecoder() transform.Transformer {
return new(iso2022JPDecoder)
}
func iso2022JPNewEncoder() transform.Transformer {
return new(iso2022JPEncoder)
}
var errInvalidISO2022JP = errors.New("japanese: invalid ISO-2022-JP encoding")
const (
asciiState = iota
katakanaState
jis0208State
jis0212State
)
const asciiEsc = 0x1b
type iso2022JPDecoder int
func (d *iso2022JPDecoder) Reset() {
*d = asciiState
}
func (d *iso2022JPDecoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
r, size := rune(0), 0
loop:
for ; nSrc < len(src); nSrc += size {
c0 := src[nSrc]
if c0 >= utf8.RuneSelf {
err = errInvalidISO2022JP
break loop
}
if c0 == asciiEsc {
if nSrc+2 >= len(src) {
err = transform.ErrShortSrc
break loop
}
size = 3
c1 := src[nSrc+1]
c2 := src[nSrc+2]
switch {
case c1 == '$' && (c2 == '@' || c2 == 'B'):
*d = jis0208State
continue
case c1 == '$' && c2 == '(':
if nSrc+3 >= len(src) {
err = transform.ErrShortSrc
break loop
}
size = 4
if src[nSrc]+3 == 'D' {
*d = jis0212State
continue
}
case c1 == '(' && (c2 == 'B' || c2 == 'J'):
*d = asciiState
continue
case c1 == '(' && c2 == 'I':
*d = katakanaState
continue
}
err = errInvalidISO2022JP
break loop
}
switch *d {
case asciiState:
r, size = rune(c0), 1
case katakanaState:
if c0 < 0x21 || 0x60 <= c0 {
err = errInvalidISO2022JP
break loop
}
r, size = rune(c0)+(0xff61-0x21), 1
default:
if c0 == 0x0a {
*d = asciiState
r, size = rune(c0), 1
break
}
if nSrc+1 >= len(src) {
err = transform.ErrShortSrc
break loop
}
size = 2
c1 := src[nSrc+1]
i := int(c0-0x21)*94 + int(c1-0x21)
if *d == jis0208State && i < len(jis0208Decode) {
r = rune(jis0208Decode[i])
} else if *d == jis0212State && i < len(jis0212Decode) {
r = rune(jis0212Decode[i])
} else {
r = '\ufffd'
break
}
if r == 0 {
r = '\ufffd'
}
}
if nDst+utf8.RuneLen(r) > len(dst) {
err = transform.ErrShortDst
break loop
}
nDst += utf8.EncodeRune(dst[nDst:], r)
}
if atEOF && err == transform.ErrShortSrc {
err = errInvalidISO2022JP
}
return nDst, nSrc, err
}
type iso2022JPEncoder int
func (e *iso2022JPEncoder) Reset() {
*e = asciiState
}
func (e *iso2022JPEncoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
r, size := rune(0), 0
for ; nSrc < len(src); nSrc += size {
r = rune(src[nSrc])
// Decode a 1-byte rune.
if r < utf8.RuneSelf {
size = 1
} else {
// Decode a multi-byte rune.
r, size = utf8.DecodeRune(src[nSrc:])
if size == 1 {
// All valid runes of size 1 (those below utf8.RuneSelf) were
// handled above. We have invalid UTF-8 or we haven't seen the
// full character yet.
if !atEOF && !utf8.FullRune(src[nSrc:]) {
err = transform.ErrShortSrc
break
}
}
// func init checks that the switch covers all tables.
//
// http://encoding.spec.whatwg.org/#iso-2022-jp says that "the index jis0212
// is not used by the iso-2022-jp encoder due to lack of widespread support".
//
// TODO: do we have to special-case U+00A5 and U+203E, as per
// http://encoding.spec.whatwg.org/#iso-2022-jp
// Doing so would mean that "\u00a5" would not be preserved
// after an encode-decode round trip.
switch {
case encode0Low <= r && r < encode0High:
if r = rune(encode0[r-encode0Low]); r>>tableShift == jis0208 {
goto writeJIS
}
case encode1Low <= r && r < encode1High:
if r = rune(encode1[r-encode1Low]); r>>tableShift == jis0208 {
goto writeJIS
}
case encode2Low <= r && r < encode2High:
if r = rune(encode2[r-encode2Low]); r>>tableShift == jis0208 {
goto writeJIS
}
case encode3Low <= r && r < encode3High:
if r = rune(encode3[r-encode3Low]); r>>tableShift == jis0208 {
goto writeJIS
}
case encode4Low <= r && r < encode4High:
if r = rune(encode4[r-encode4Low]); r>>tableShift == jis0208 {
goto writeJIS
}
case encode5Low <= r && r < encode5High:
if 0xff61 <= r && r < 0xffa0 {
goto writeKatakana
}
if r = rune(encode5[r-encode5Low]); r>>tableShift == jis0208 {
goto writeJIS
}
}
// Switch back to ASCII state in case of error so that an ASCII
// replacement character can be written in the correct state.
if *e != asciiState {
if nDst+3 > len(dst) {
err = transform.ErrShortDst
break
}
*e = asciiState
dst[nDst+0] = asciiEsc
dst[nDst+1] = '('
dst[nDst+2] = 'B'
nDst += 3
}
err = internal.ErrASCIIReplacement
break
}
if *e != asciiState {
if nDst+4 > len(dst) {
err = transform.ErrShortDst
break
}
*e = asciiState
dst[nDst+0] = asciiEsc
dst[nDst+1] = '('
dst[nDst+2] = 'B'
nDst += 3
} else if nDst >= len(dst) {
err = transform.ErrShortDst
break
}
dst[nDst] = uint8(r)
nDst++
continue
writeJIS:
if *e != jis0208State {
if nDst+5 > len(dst) {
err = transform.ErrShortDst
break
}
*e = jis0208State
dst[nDst+0] = asciiEsc
dst[nDst+1] = '$'
dst[nDst+2] = 'B'
nDst += 3
} else if nDst+2 > len(dst) {
err = transform.ErrShortDst
break
}
dst[nDst+0] = 0x21 + uint8(r>>codeShift)&codeMask
dst[nDst+1] = 0x21 + uint8(r)&codeMask
nDst += 2
continue
writeKatakana:
if *e != katakanaState {
if nDst+4 > len(dst) {
err = transform.ErrShortDst
break
}
*e = katakanaState
dst[nDst+0] = asciiEsc
dst[nDst+1] = '('
dst[nDst+2] = 'I'
nDst += 3
} else if nDst >= len(dst) {
err = transform.ErrShortDst
break
}
dst[nDst] = uint8(r - (0xff61 - 0x21))
nDst++
continue
}
if atEOF && err == nil && *e != asciiState {
if nDst+3 > len(dst) {
err = transform.ErrShortDst
} else {
*e = asciiState
dst[nDst+0] = asciiEsc
dst[nDst+1] = '('
dst[nDst+2] = 'B'
nDst += 3
}
}
return nDst, nSrc, err
}

View File

@ -0,0 +1,161 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
package main
// This program generates tables.go:
// go run maketables.go | gofmt > tables.go
// TODO: Emoji extensions?
// http://www.unicode.org/faq/emoji_dingbats.html
// http://www.unicode.org/Public/UNIDATA/EmojiSources.txt
import (
"bufio"
"fmt"
"log"
"net/http"
"sort"
"strings"
)
type entry struct {
jisCode, table int
}
func main() {
fmt.Printf("// generated by go run maketables.go; DO NOT EDIT\n\n")
fmt.Printf("// Package japanese provides Japanese encodings such as EUC-JP and Shift JIS.\n")
fmt.Printf(`package japanese // import "golang.org/x/text/encoding/japanese"` + "\n\n")
reverse := [65536]entry{}
for i := range reverse {
reverse[i].table = -1
}
tables := []struct {
url string
name string
}{
{"http://encoding.spec.whatwg.org/index-jis0208.txt", "0208"},
{"http://encoding.spec.whatwg.org/index-jis0212.txt", "0212"},
}
for i, table := range tables {
res, err := http.Get(table.url)
if err != nil {
log.Fatalf("%q: Get: %v", table.url, err)
}
defer res.Body.Close()
mapping := [65536]uint16{}
scanner := bufio.NewScanner(res.Body)
for scanner.Scan() {
s := strings.TrimSpace(scanner.Text())
if s == "" || s[0] == '#' {
continue
}
x, y := 0, uint16(0)
if _, err := fmt.Sscanf(s, "%d 0x%x", &x, &y); err != nil {
log.Fatalf("%q: could not parse %q", table.url, s)
}
if x < 0 || 120*94 <= x {
log.Fatalf("%q: JIS code %d is out of range", table.url, x)
}
mapping[x] = y
if reverse[y].table == -1 {
reverse[y] = entry{jisCode: x, table: i}
}
}
if err := scanner.Err(); err != nil {
log.Fatalf("%q: scanner error: %v", table.url, err)
}
fmt.Printf("// jis%sDecode is the decoding table from JIS %s code to Unicode.\n// It is defined at %s\n",
table.name, table.name, table.url)
fmt.Printf("var jis%sDecode = [...]uint16{\n", table.name)
for i, m := range mapping {
if m != 0 {
fmt.Printf("\t%d: 0x%04X,\n", i, m)
}
}
fmt.Printf("}\n\n")
}
// Any run of at least separation continuous zero entries in the reverse map will
// be a separate encode table.
const separation = 1024
intervals := []interval(nil)
low, high := -1, -1
for i, v := range reverse {
if v.table == -1 {
continue
}
if low < 0 {
low = i
} else if i-high >= separation {
if high >= 0 {
intervals = append(intervals, interval{low, high})
}
low = i
}
high = i + 1
}
if high >= 0 {
intervals = append(intervals, interval{low, high})
}
sort.Sort(byDecreasingLength(intervals))
fmt.Printf("const (\n")
fmt.Printf("\tjis0208 = 1\n")
fmt.Printf("\tjis0212 = 2\n")
fmt.Printf("\tcodeMask = 0x7f\n")
fmt.Printf("\tcodeShift = 7\n")
fmt.Printf("\ttableShift = 14\n")
fmt.Printf(")\n\n")
fmt.Printf("const numEncodeTables = %d\n\n", len(intervals))
fmt.Printf("// encodeX are the encoding tables from Unicode to JIS code,\n")
fmt.Printf("// sorted by decreasing length.\n")
for i, v := range intervals {
fmt.Printf("// encode%d: %5d entries for runes in [%5d, %5d).\n", i, v.len(), v.low, v.high)
}
fmt.Printf("//\n")
fmt.Printf("// The high two bits of the value record whether the JIS code comes from the\n")
fmt.Printf("// JIS0208 table (high bits == 1) or the JIS0212 table (high bits == 2).\n")
fmt.Printf("// The low 14 bits are two 7-bit unsigned integers j1 and j2 that form the\n")
fmt.Printf("// JIS code (94*j1 + j2) within that table.\n")
fmt.Printf("\n")
for i, v := range intervals {
fmt.Printf("const encode%dLow, encode%dHigh = %d, %d\n\n", i, i, v.low, v.high)
fmt.Printf("var encode%d = [...]uint16{\n", i)
for j := v.low; j < v.high; j++ {
x := reverse[j]
if x.table == -1 {
continue
}
fmt.Printf("\t%d - %d: jis%s<<14 | 0x%02X<<7 | 0x%02X,\n",
j, v.low, tables[x.table].name, x.jisCode/94, x.jisCode%94)
}
fmt.Printf("}\n\n")
}
}
// interval is a half-open interval [low, high).
type interval struct {
low, high int
}
func (i interval) len() int { return i.high - i.low }
// byDecreasingLength sorts intervals by decreasing length.
type byDecreasingLength []interval
func (b byDecreasingLength) Len() int { return len(b) }
func (b byDecreasingLength) Less(i, j int) bool { return b[i].len() > b[j].len() }
func (b byDecreasingLength) Swap(i, j int) { b[i], b[j] = b[j], b[i] }

189
vendor/golang.org/x/text/encoding/japanese/shiftjis.go generated vendored Normal file
View File

@ -0,0 +1,189 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package japanese
import (
"errors"
"unicode/utf8"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/internal"
"golang.org/x/text/encoding/internal/identifier"
"golang.org/x/text/transform"
)
// ShiftJIS is the Shift JIS encoding, also known as Code Page 932 and
// Windows-31J.
var ShiftJIS encoding.Encoding = &shiftJIS
var shiftJIS = internal.Encoding{
&internal.SimpleEncoding{shiftJISDecoder{}, shiftJISEncoder{}},
"Shift JIS",
identifier.ShiftJIS,
}
var errInvalidShiftJIS = errors.New("japanese: invalid Shift JIS encoding")
type shiftJISDecoder struct{ transform.NopResetter }
func (shiftJISDecoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
r, size := rune(0), 0
loop:
for ; nSrc < len(src); nSrc += size {
switch c0 := src[nSrc]; {
case c0 < utf8.RuneSelf:
r, size = rune(c0), 1
case 0xa1 <= c0 && c0 < 0xe0:
r, size = rune(c0)+(0xff61-0xa1), 1
case (0x81 <= c0 && c0 < 0xa0) || (0xe0 <= c0 && c0 < 0xfd):
if c0 <= 0x9f {
c0 -= 0x70
} else {
c0 -= 0xb0
}
c0 = 2*c0 - 0x21
if nSrc+1 >= len(src) {
err = transform.ErrShortSrc
break loop
}
c1 := src[nSrc+1]
switch {
case c1 < 0x40:
err = errInvalidShiftJIS
break loop
case c1 < 0x7f:
c0--
c1 -= 0x40
case c1 == 0x7f:
err = errInvalidShiftJIS
break loop
case c1 < 0x9f:
c0--
c1 -= 0x41
case c1 < 0xfd:
c1 -= 0x9f
default:
err = errInvalidShiftJIS
break loop
}
r, size = '\ufffd', 2
if i := int(c0)*94 + int(c1); i < len(jis0208Decode) {
r = rune(jis0208Decode[i])
if r == 0 {
r = '\ufffd'
}
}
default:
err = errInvalidShiftJIS
break loop
}
if nDst+utf8.RuneLen(r) > len(dst) {
err = transform.ErrShortDst
break loop
}
nDst += utf8.EncodeRune(dst[nDst:], r)
}
if atEOF && err == transform.ErrShortSrc {
err = errInvalidShiftJIS
}
return nDst, nSrc, err
}
type shiftJISEncoder struct{ transform.NopResetter }
func (shiftJISEncoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
r, size := rune(0), 0
loop:
for ; nSrc < len(src); nSrc += size {
r = rune(src[nSrc])
// Decode a 1-byte rune.
if r < utf8.RuneSelf {
size = 1
} else {
// Decode a multi-byte rune.
r, size = utf8.DecodeRune(src[nSrc:])
if size == 1 {
// All valid runes of size 1 (those below utf8.RuneSelf) were
// handled above. We have invalid UTF-8 or we haven't seen the
// full character yet.
if !atEOF && !utf8.FullRune(src[nSrc:]) {
err = transform.ErrShortSrc
break loop
}
}
// func init checks that the switch covers all tables.
switch {
case encode0Low <= r && r < encode0High:
if r = rune(encode0[r-encode0Low]); r>>tableShift == jis0208 {
goto write2
}
case encode1Low <= r && r < encode1High:
if r = rune(encode1[r-encode1Low]); r>>tableShift == jis0208 {
goto write2
}
case encode2Low <= r && r < encode2High:
if r = rune(encode2[r-encode2Low]); r>>tableShift == jis0208 {
goto write2
}
case encode3Low <= r && r < encode3High:
if r = rune(encode3[r-encode3Low]); r>>tableShift == jis0208 {
goto write2
}
case encode4Low <= r && r < encode4High:
if r = rune(encode4[r-encode4Low]); r>>tableShift == jis0208 {
goto write2
}
case encode5Low <= r && r < encode5High:
if 0xff61 <= r && r < 0xffa0 {
r -= 0xff61 - 0xa1
goto write1
}
if r = rune(encode5[r-encode5Low]); r>>tableShift == jis0208 {
goto write2
}
}
err = internal.ErrASCIIReplacement
break
}
write1:
if nDst >= len(dst) {
err = transform.ErrShortDst
break
}
dst[nDst] = uint8(r)
nDst++
continue
write2:
j1 := uint8(r>>codeShift) & codeMask
j2 := uint8(r) & codeMask
if nDst+2 > len(dst) {
err = transform.ErrShortDst
break loop
}
if j1 <= 61 {
dst[nDst+0] = 129 + j1/2
} else {
dst[nDst+0] = 193 + j1/2
}
if j1&1 == 0 {
dst[nDst+1] = j2 + j2/63 + 64
} else {
dst[nDst+1] = j2 + 159
}
nDst += 2
continue
}
return nDst, nSrc, err
}

26971
vendor/golang.org/x/text/encoding/japanese/tables.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

47
vendor/golang.org/x/text/encoding/korean/all_test.go generated vendored Normal file
View File

@ -0,0 +1,47 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package korean
import (
"testing"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/internal"
"golang.org/x/text/transform"
)
func dec(e encoding.Encoding) (dir string, t transform.Transformer, err error) {
return "Decode", e.NewDecoder(), nil
}
func enc(e encoding.Encoding) (dir string, t transform.Transformer, err error) {
return "Encode", e.NewEncoder(), internal.ErrASCIIReplacement
}
func TestNonRepertoire(t *testing.T) {
testCases := []struct {
init func(e encoding.Encoding) (string, transform.Transformer, error)
e encoding.Encoding
src, want string
}{
{dec, EUCKR, "\xfe\xfe", "\ufffd"},
// {dec, EUCKR, "א", "\ufffd"}, // TODO: why is this different?
{enc, EUCKR, "א", ""},
{enc, EUCKR, "aא", "a"},
{enc, EUCKR, "\uac00א", "\xb0\xa1"},
// TODO: should we also handle Jamo?
}
for _, tc := range testCases {
dir, tr, wantErr := tc.init(tc.e)
dst, _, err := transform.String(tr, tc.src)
if err != wantErr {
t.Errorf("%s %v(%q): got %v; want %v", dir, tc.e, tc.src, err, wantErr)
}
if got := string(dst); got != tc.want {
t.Errorf("%s %v(%q):\ngot %q\nwant %q", dir, tc.e, tc.src, got, tc.want)
}
}
}

178
vendor/golang.org/x/text/encoding/korean/euckr.go generated vendored Normal file
View File

@ -0,0 +1,178 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package korean
import (
"errors"
"unicode/utf8"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/internal"
"golang.org/x/text/encoding/internal/identifier"
"golang.org/x/text/transform"
)
// All is a list of all defined encodings in this package.
var All = []encoding.Encoding{EUCKR}
// EUCKR is the EUC-KR encoding, also known as Code Page 949.
var EUCKR encoding.Encoding = &eucKR
var eucKR = internal.Encoding{
&internal.SimpleEncoding{eucKRDecoder{}, eucKREncoder{}},
"EUC-KR",
identifier.EUCKR,
}
var errInvalidEUCKR = errors.New("korean: invalid EUC-KR encoding")
type eucKRDecoder struct{ transform.NopResetter }
func (eucKRDecoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
r, size := rune(0), 0
loop:
for ; nSrc < len(src); nSrc += size {
switch c0 := src[nSrc]; {
case c0 < utf8.RuneSelf:
r, size = rune(c0), 1
case 0x81 <= c0 && c0 < 0xff:
if nSrc+1 >= len(src) {
err = transform.ErrShortSrc
break loop
}
c1 := src[nSrc+1]
if c0 < 0xc7 {
r = 178 * rune(c0-0x81)
switch {
case 0x41 <= c1 && c1 < 0x5b:
r += rune(c1) - (0x41 - 0*26)
case 0x61 <= c1 && c1 < 0x7b:
r += rune(c1) - (0x61 - 1*26)
case 0x81 <= c1 && c1 < 0xff:
r += rune(c1) - (0x81 - 2*26)
default:
err = errInvalidEUCKR
break loop
}
} else if 0xa1 <= c1 && c1 < 0xff {
r = 178*(0xc7-0x81) + rune(c0-0xc7)*94 + rune(c1-0xa1)
} else {
err = errInvalidEUCKR
break loop
}
if int(r) < len(decode) {
r = rune(decode[r])
if r == 0 {
r = '\ufffd'
}
} else {
r = '\ufffd'
}
size = 2
default:
err = errInvalidEUCKR
break loop
}
if nDst+utf8.RuneLen(r) > len(dst) {
err = transform.ErrShortDst
break loop
}
nDst += utf8.EncodeRune(dst[nDst:], r)
}
if atEOF && err == transform.ErrShortSrc {
err = errInvalidEUCKR
}
return nDst, nSrc, err
}
type eucKREncoder struct{ transform.NopResetter }
func (eucKREncoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
r, size := rune(0), 0
for ; nSrc < len(src); nSrc += size {
r = rune(src[nSrc])
// Decode a 1-byte rune.
if r < utf8.RuneSelf {
size = 1
if nDst >= len(dst) {
err = transform.ErrShortDst
break
}
dst[nDst] = uint8(r)
nDst++
continue
} else {
// Decode a multi-byte rune.
r, size = utf8.DecodeRune(src[nSrc:])
if size == 1 {
// All valid runes of size 1 (those below utf8.RuneSelf) were
// handled above. We have invalid UTF-8 or we haven't seen the
// full character yet.
if !atEOF && !utf8.FullRune(src[nSrc:]) {
err = transform.ErrShortSrc
break
}
}
// func init checks that the switch covers all tables.
switch {
case encode0Low <= r && r < encode0High:
if r = rune(encode0[r-encode0Low]); r != 0 {
goto write2
}
case encode1Low <= r && r < encode1High:
if r = rune(encode1[r-encode1Low]); r != 0 {
goto write2
}
case encode2Low <= r && r < encode2High:
if r = rune(encode2[r-encode2Low]); r != 0 {
goto write2
}
case encode3Low <= r && r < encode3High:
if r = rune(encode3[r-encode3Low]); r != 0 {
goto write2
}
case encode4Low <= r && r < encode4High:
if r = rune(encode4[r-encode4Low]); r != 0 {
goto write2
}
case encode5Low <= r && r < encode5High:
if r = rune(encode5[r-encode5Low]); r != 0 {
goto write2
}
case encode6Low <= r && r < encode6High:
if r = rune(encode6[r-encode6Low]); r != 0 {
goto write2
}
}
err = internal.ErrASCIIReplacement
break
}
write2:
if nDst+2 > len(dst) {
err = transform.ErrShortDst
break
}
dst[nDst+0] = uint8(r >> 8)
dst[nDst+1] = uint8(r)
nDst += 2
continue
}
return nDst, nSrc, err
}
func init() {
// Check that the hard-coded encode switch covers all tables.
if numEncodeTables != 7 {
panic("bad numEncodeTables")
}
}

143
vendor/golang.org/x/text/encoding/korean/maketables.go generated vendored Normal file
View File

@ -0,0 +1,143 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
package main
// This program generates tables.go:
// go run maketables.go | gofmt > tables.go
import (
"bufio"
"fmt"
"log"
"net/http"
"sort"
"strings"
)
func main() {
fmt.Printf("// generated by go run maketables.go; DO NOT EDIT\n\n")
fmt.Printf("// Package korean provides Korean encodings such as EUC-KR.\n")
fmt.Printf(`package korean // import "golang.org/x/text/encoding/korean"` + "\n\n")
res, err := http.Get("http://encoding.spec.whatwg.org/index-euc-kr.txt")
if err != nil {
log.Fatalf("Get: %v", err)
}
defer res.Body.Close()
mapping := [65536]uint16{}
reverse := [65536]uint16{}
scanner := bufio.NewScanner(res.Body)
for scanner.Scan() {
s := strings.TrimSpace(scanner.Text())
if s == "" || s[0] == '#' {
continue
}
x, y := uint16(0), uint16(0)
if _, err := fmt.Sscanf(s, "%d 0x%x", &x, &y); err != nil {
log.Fatalf("could not parse %q", s)
}
if x < 0 || 178*(0xc7-0x81)+(0xfe-0xc7)*94+(0xff-0xa1) <= x {
log.Fatalf("EUC-KR code %d is out of range", x)
}
mapping[x] = y
if reverse[y] == 0 {
c0, c1 := uint16(0), uint16(0)
if x < 178*(0xc7-0x81) {
c0 = uint16(x/178) + 0x81
c1 = uint16(x % 178)
switch {
case c1 < 1*26:
c1 += 0x41
case c1 < 2*26:
c1 += 0x47
default:
c1 += 0x4d
}
} else {
x -= 178 * (0xc7 - 0x81)
c0 = uint16(x/94) + 0xc7
c1 = uint16(x%94) + 0xa1
}
reverse[y] = c0<<8 | c1
}
}
if err := scanner.Err(); err != nil {
log.Fatalf("scanner error: %v", err)
}
fmt.Printf("// decode is the decoding table from EUC-KR code to Unicode.\n")
fmt.Printf("// It is defined at http://encoding.spec.whatwg.org/index-euc-kr.txt\n")
fmt.Printf("var decode = [...]uint16{\n")
for i, v := range mapping {
if v != 0 {
fmt.Printf("\t%d: 0x%04X,\n", i, v)
}
}
fmt.Printf("}\n\n")
// Any run of at least separation continuous zero entries in the reverse map will
// be a separate encode table.
const separation = 1024
intervals := []interval(nil)
low, high := -1, -1
for i, v := range reverse {
if v == 0 {
continue
}
if low < 0 {
low = i
} else if i-high >= separation {
if high >= 0 {
intervals = append(intervals, interval{low, high})
}
low = i
}
high = i + 1
}
if high >= 0 {
intervals = append(intervals, interval{low, high})
}
sort.Sort(byDecreasingLength(intervals))
fmt.Printf("const numEncodeTables = %d\n\n", len(intervals))
fmt.Printf("// encodeX are the encoding tables from Unicode to EUC-KR code,\n")
fmt.Printf("// sorted by decreasing length.\n")
for i, v := range intervals {
fmt.Printf("// encode%d: %5d entries for runes in [%5d, %5d).\n", i, v.len(), v.low, v.high)
}
fmt.Printf("\n")
for i, v := range intervals {
fmt.Printf("const encode%dLow, encode%dHigh = %d, %d\n\n", i, i, v.low, v.high)
fmt.Printf("var encode%d = [...]uint16{\n", i)
for j := v.low; j < v.high; j++ {
x := reverse[j]
if x == 0 {
continue
}
fmt.Printf("\t%d-%d: 0x%04X,\n", j, v.low, x)
}
fmt.Printf("}\n\n")
}
}
// interval is a half-open interval [low, high).
type interval struct {
low, high int
}
func (i interval) len() int { return i.high - i.low }
// byDecreasingLength sorts intervals by decreasing length.
type byDecreasingLength []interval
func (b byDecreasingLength) Len() int { return len(b) }
func (b byDecreasingLength) Less(i, j int) bool { return b[i].len() > b[j].len() }
func (b byDecreasingLength) Swap(i, j int) { b[i], b[j] = b[j], b[i] }

34152
vendor/golang.org/x/text/encoding/korean/tables.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,12 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package simplifiedchinese
import (
"golang.org/x/text/encoding"
)
// All is a list of all defined encodings in this package.
var All = []encoding.Encoding{GB18030, GBK, HZGB2312}

View File

@ -0,0 +1,50 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package simplifiedchinese
import (
"testing"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/internal"
"golang.org/x/text/transform"
)
func dec(e encoding.Encoding) (dir string, t transform.Transformer, err error) {
return "Decode", e.NewDecoder(), nil
}
func enc(e encoding.Encoding) (dir string, t transform.Transformer, err error) {
return "Encode", e.NewEncoder(), internal.ErrASCIIReplacement
}
func TestNonRepertoire(t *testing.T) {
testCases := []struct {
init func(e encoding.Encoding) (string, transform.Transformer, error)
e encoding.Encoding
src, want string
}{
{dec, GBK, "a\xfe\xfeb", "a\ufffdb"},
{dec, HZGB2312, "~{z~", "\ufffd"},
{enc, GBK, "갂", ""},
{enc, GBK, "a갂", "a"},
{enc, GBK, "\u4e02갂", "\x81@"},
{enc, HZGB2312, "갂", ""},
{enc, HZGB2312, "a갂", "a"},
{enc, HZGB2312, "\u6cf5갂", "~{1C~}"},
}
for _, tc := range testCases {
dir, tr, wantErr := tc.init(tc.e)
dst, _, err := transform.String(tr, tc.src)
if err != wantErr {
t.Errorf("%s %v(%q): got %v; want %v", dir, tc.e, tc.src, err, wantErr)
}
if got := string(dst); got != tc.want {
t.Errorf("%s %v(%q):\ngot %q\nwant %q", dir, tc.e, tc.src, got, tc.want)
}
}
}

View File

@ -0,0 +1,281 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package simplifiedchinese
import (
"errors"
"unicode/utf8"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/internal"
"golang.org/x/text/encoding/internal/identifier"
"golang.org/x/text/transform"
)
var (
// GB18030 is the GB18030 encoding.
GB18030 encoding.Encoding = &gbk18030
// GBK is the GBK encoding. It encodes an extension of the GB2312 character set
// and is also known as Code Page 936.
GBK encoding.Encoding = &gbk
)
var gbk = internal.Encoding{
&internal.SimpleEncoding{
gbkDecoder{gb18030: false},
gbkEncoder{gb18030: false},
},
"GBK",
identifier.GBK,
}
var gbk18030 = internal.Encoding{
&internal.SimpleEncoding{
gbkDecoder{gb18030: true},
gbkEncoder{gb18030: true},
},
"GB18030",
identifier.GB18030,
}
var (
errInvalidGB18030 = errors.New("simplifiedchinese: invalid GB18030 encoding")
errInvalidGBK = errors.New("simplifiedchinese: invalid GBK encoding")
)
type gbkDecoder struct {
transform.NopResetter
gb18030 bool
}
func (d gbkDecoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
r, size := rune(0), 0
loop:
for ; nSrc < len(src); nSrc += size {
switch c0 := src[nSrc]; {
case c0 < utf8.RuneSelf:
r, size = rune(c0), 1
// Microsoft's Code Page 936 extends GBK 1.0 to encode the euro sign U+20AC
// as 0x80. The HTML5 specification at http://encoding.spec.whatwg.org/#gbk
// says to treat "gbk" as Code Page 936.
case c0 == 0x80:
r, size = '€', 1
case c0 < 0xff:
if nSrc+1 >= len(src) {
err = transform.ErrShortSrc
break loop
}
c1 := src[nSrc+1]
switch {
case 0x40 <= c1 && c1 < 0x7f:
c1 -= 0x40
case 0x80 <= c1 && c1 < 0xff:
c1 -= 0x41
case d.gb18030 && 0x30 <= c1 && c1 < 0x40:
if nSrc+3 >= len(src) {
err = transform.ErrShortSrc
break loop
}
c2 := src[nSrc+2]
if c2 < 0x81 || 0xff <= c2 {
err = errInvalidGB18030
break loop
}
c3 := src[nSrc+3]
if c3 < 0x30 || 0x3a <= c3 {
err = errInvalidGB18030
break loop
}
size = 4
r = ((rune(c0-0x81)*10+rune(c1-0x30))*126+rune(c2-0x81))*10 + rune(c3-0x30)
if r < 39420 {
i, j := 0, len(gb18030)
for i < j {
h := i + (j-i)/2
if r >= rune(gb18030[h][0]) {
i = h + 1
} else {
j = h
}
}
dec := &gb18030[i-1]
r += rune(dec[1]) - rune(dec[0])
goto write
}
r -= 189000
if 0 <= r && r < 0x100000 {
r += 0x10000
goto write
}
err = errInvalidGB18030
break loop
default:
if d.gb18030 {
err = errInvalidGB18030
} else {
err = errInvalidGBK
}
break loop
}
r, size = '\ufffd', 2
if i := int(c0-0x81)*190 + int(c1); i < len(decode) {
r = rune(decode[i])
if r == 0 {
r = '\ufffd'
}
}
default:
if d.gb18030 {
err = errInvalidGB18030
} else {
err = errInvalidGBK
}
break loop
}
write:
if nDst+utf8.RuneLen(r) > len(dst) {
err = transform.ErrShortDst
break loop
}
nDst += utf8.EncodeRune(dst[nDst:], r)
}
if atEOF && err == transform.ErrShortSrc {
if d.gb18030 {
err = errInvalidGB18030
} else {
err = errInvalidGBK
}
}
return nDst, nSrc, err
}
type gbkEncoder struct {
transform.NopResetter
gb18030 bool
}
func (e gbkEncoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
r, r2, size := rune(0), rune(0), 0
for ; nSrc < len(src); nSrc += size {
r = rune(src[nSrc])
// Decode a 1-byte rune.
if r < utf8.RuneSelf {
size = 1
} else {
// Decode a multi-byte rune.
r, size = utf8.DecodeRune(src[nSrc:])
if size == 1 {
// All valid runes of size 1 (those below utf8.RuneSelf) were
// handled above. We have invalid UTF-8 or we haven't seen the
// full character yet.
if !atEOF && !utf8.FullRune(src[nSrc:]) {
err = transform.ErrShortSrc
break
}
}
// func init checks that the switch covers all tables.
switch {
case encode0Low <= r && r < encode0High:
if r2 = rune(encode0[r-encode0Low]); r2 != 0 {
goto write2
}
case encode1Low <= r && r < encode1High:
// Microsoft's Code Page 936 extends GBK 1.0 to encode the euro sign U+20AC
// as 0x80. The HTML5 specification at http://encoding.spec.whatwg.org/#gbk
// says to treat "gbk" as Code Page 936.
if r == '€' {
r = 0x80
goto write1
}
if r2 = rune(encode1[r-encode1Low]); r2 != 0 {
goto write2
}
case encode2Low <= r && r < encode2High:
if r2 = rune(encode2[r-encode2Low]); r2 != 0 {
goto write2
}
case encode3Low <= r && r < encode3High:
if r2 = rune(encode3[r-encode3Low]); r2 != 0 {
goto write2
}
case encode4Low <= r && r < encode4High:
if r2 = rune(encode4[r-encode4Low]); r2 != 0 {
goto write2
}
}
if e.gb18030 {
if r < 0x10000 {
i, j := 0, len(gb18030)
for i < j {
h := i + (j-i)/2
if r >= rune(gb18030[h][1]) {
i = h + 1
} else {
j = h
}
}
dec := &gb18030[i-1]
r += rune(dec[0]) - rune(dec[1])
goto write4
} else if r < 0x110000 {
r += 189000 - 0x10000
goto write4
}
}
err = internal.ErrASCIIReplacement
break
}
write1:
if nDst >= len(dst) {
err = transform.ErrShortDst
break
}
dst[nDst] = uint8(r)
nDst++
continue
write2:
if nDst+2 > len(dst) {
err = transform.ErrShortDst
break
}
dst[nDst+0] = uint8(r2 >> 8)
dst[nDst+1] = uint8(r2)
nDst += 2
continue
write4:
if nDst+4 > len(dst) {
err = transform.ErrShortDst
break
}
dst[nDst+3] = uint8(r%10 + 0x30)
r /= 10
dst[nDst+2] = uint8(r%126 + 0x81)
r /= 126
dst[nDst+1] = uint8(r%10 + 0x30)
r /= 10
dst[nDst+0] = uint8(r + 0x81)
nDst += 4
continue
}
return nDst, nSrc, err
}
func init() {
// Check that the hard-coded encode switch covers all tables.
if numEncodeTables != 5 {
panic("bad numEncodeTables")
}
}

View File

@ -0,0 +1,240 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package simplifiedchinese
import (
"errors"
"unicode/utf8"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/internal"
"golang.org/x/text/encoding/internal/identifier"
"golang.org/x/text/transform"
)
// HZGB2312 is the HZ-GB2312 encoding.
var HZGB2312 encoding.Encoding = &hzGB2312
var hzGB2312 = internal.Encoding{
internal.FuncEncoding{hzGB2312NewDecoder, hzGB2312NewEncoder},
"HZ-GB2312",
identifier.HZGB2312,
}
func hzGB2312NewDecoder() transform.Transformer {
return new(hzGB2312Decoder)
}
func hzGB2312NewEncoder() transform.Transformer {
return new(hzGB2312Encoder)
}
var errInvalidHZGB2312 = errors.New("simplifiedchinese: invalid HZ-GB2312 encoding")
const (
asciiState = iota
gbState
)
type hzGB2312Decoder int
func (d *hzGB2312Decoder) Reset() {
*d = asciiState
}
func (d *hzGB2312Decoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
r, size := rune(0), 0
loop:
for ; nSrc < len(src); nSrc += size {
c0 := src[nSrc]
if c0 >= utf8.RuneSelf {
err = errInvalidHZGB2312
break loop
}
if c0 == '~' {
if nSrc+1 >= len(src) {
err = transform.ErrShortSrc
break loop
}
size = 2
switch src[nSrc+1] {
case '{':
*d = gbState
continue
case '}':
*d = asciiState
continue
case '~':
if nDst >= len(dst) {
err = transform.ErrShortDst
break loop
}
dst[nDst] = '~'
nDst++
continue
case '\n':
continue
default:
err = errInvalidHZGB2312
break loop
}
}
if *d == asciiState {
r, size = rune(c0), 1
} else {
if nSrc+1 >= len(src) {
err = transform.ErrShortSrc
break loop
}
c1 := src[nSrc+1]
if c0 < 0x21 || 0x7e <= c0 || c1 < 0x21 || 0x7f <= c1 {
err = errInvalidHZGB2312
break loop
}
r, size = '\ufffd', 2
if i := int(c0-0x01)*190 + int(c1+0x3f); i < len(decode) {
r = rune(decode[i])
if r == 0 {
r = '\ufffd'
}
}
}
if nDst+utf8.RuneLen(r) > len(dst) {
err = transform.ErrShortDst
break loop
}
nDst += utf8.EncodeRune(dst[nDst:], r)
}
if atEOF && err == transform.ErrShortSrc {
err = errInvalidHZGB2312
}
return nDst, nSrc, err
}
type hzGB2312Encoder int
func (d *hzGB2312Encoder) Reset() {
*d = asciiState
}
func (e *hzGB2312Encoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
r, size := rune(0), 0
for ; nSrc < len(src); nSrc += size {
r = rune(src[nSrc])
// Decode a 1-byte rune.
if r < utf8.RuneSelf {
size = 1
if r == '~' {
if nDst+2 > len(dst) {
err = transform.ErrShortDst
break
}
dst[nDst+0] = '~'
dst[nDst+1] = '~'
nDst += 2
continue
} else if *e != asciiState {
if nDst+3 > len(dst) {
err = transform.ErrShortDst
break
}
*e = asciiState
dst[nDst+0] = '~'
dst[nDst+1] = '}'
nDst += 2
} else if nDst >= len(dst) {
err = transform.ErrShortDst
break
}
dst[nDst] = uint8(r)
nDst += 1
continue
}
// Decode a multi-byte rune.
r, size = utf8.DecodeRune(src[nSrc:])
if size == 1 {
// All valid runes of size 1 (those below utf8.RuneSelf) were
// handled above. We have invalid UTF-8 or we haven't seen the
// full character yet.
if !atEOF && !utf8.FullRune(src[nSrc:]) {
err = transform.ErrShortSrc
break
}
}
// func init checks that the switch covers all tables.
switch {
case encode0Low <= r && r < encode0High:
if r = rune(encode0[r-encode0Low]); r != 0 {
goto writeGB
}
case encode1Low <= r && r < encode1High:
if r = rune(encode1[r-encode1Low]); r != 0 {
goto writeGB
}
case encode2Low <= r && r < encode2High:
if r = rune(encode2[r-encode2Low]); r != 0 {
goto writeGB
}
case encode3Low <= r && r < encode3High:
if r = rune(encode3[r-encode3Low]); r != 0 {
goto writeGB
}
case encode4Low <= r && r < encode4High:
if r = rune(encode4[r-encode4Low]); r != 0 {
goto writeGB
}
}
terminateInASCIIState:
// Switch back to ASCII state in case of error so that an ASCII
// replacement character can be written in the correct state.
if *e != asciiState {
if nDst+2 > len(dst) {
err = transform.ErrShortDst
break
}
dst[nDst+0] = '~'
dst[nDst+1] = '}'
nDst += 2
}
err = internal.ErrASCIIReplacement
break
writeGB:
c0 := uint8(r>>8) - 0x80
c1 := uint8(r) - 0x80
if c0 < 0x21 || 0x7e <= c0 || c1 < 0x21 || 0x7f <= c1 {
goto terminateInASCIIState
}
if *e == asciiState {
if nDst+4 > len(dst) {
err = transform.ErrShortDst
break
}
*e = gbState
dst[nDst+0] = '~'
dst[nDst+1] = '{'
nDst += 2
} else if nDst+2 > len(dst) {
err = transform.ErrShortDst
break
}
dst[nDst+0] = c0
dst[nDst+1] = c1
nDst += 2
continue
}
// TODO: should one always terminate in ASCII state to make it safe to
// concatenate two HZ-GB2312-encoded strings?
return nDst, nSrc, err
}

View File

@ -0,0 +1,161 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
package main
// This program generates tables.go:
// go run maketables.go | gofmt > tables.go
import (
"bufio"
"fmt"
"log"
"net/http"
"sort"
"strings"
)
func main() {
fmt.Printf("// generated by go run maketables.go; DO NOT EDIT\n\n")
fmt.Printf("// Package simplifiedchinese provides Simplified Chinese encodings such as GBK.\n")
fmt.Printf(`package simplifiedchinese // import "golang.org/x/text/encoding/simplifiedchinese"` + "\n\n")
printGB18030()
printGBK()
}
func printGB18030() {
res, err := http.Get("http://encoding.spec.whatwg.org/index-gb18030.txt")
if err != nil {
log.Fatalf("Get: %v", err)
}
defer res.Body.Close()
fmt.Printf("// gb18030 is the table from http://encoding.spec.whatwg.org/index-gb18030.txt\n")
fmt.Printf("var gb18030 = [...][2]uint16{\n")
scanner := bufio.NewScanner(res.Body)
for scanner.Scan() {
s := strings.TrimSpace(scanner.Text())
if s == "" || s[0] == '#' {
continue
}
x, y := uint32(0), uint32(0)
if _, err := fmt.Sscanf(s, "%d 0x%x", &x, &y); err != nil {
log.Fatalf("could not parse %q", s)
}
if x < 0x10000 && y < 0x10000 {
fmt.Printf("\t{0x%04x, 0x%04x},\n", x, y)
}
}
fmt.Printf("}\n\n")
}
func printGBK() {
res, err := http.Get("http://encoding.spec.whatwg.org/index-gbk.txt")
if err != nil {
log.Fatalf("Get: %v", err)
}
defer res.Body.Close()
mapping := [65536]uint16{}
reverse := [65536]uint16{}
scanner := bufio.NewScanner(res.Body)
for scanner.Scan() {
s := strings.TrimSpace(scanner.Text())
if s == "" || s[0] == '#' {
continue
}
x, y := uint16(0), uint16(0)
if _, err := fmt.Sscanf(s, "%d 0x%x", &x, &y); err != nil {
log.Fatalf("could not parse %q", s)
}
if x < 0 || 126*190 <= x {
log.Fatalf("GBK code %d is out of range", x)
}
mapping[x] = y
if reverse[y] == 0 {
c0, c1 := x/190, x%190
if c1 >= 0x3f {
c1++
}
reverse[y] = (0x81+c0)<<8 | (0x40 + c1)
}
}
if err := scanner.Err(); err != nil {
log.Fatalf("scanner error: %v", err)
}
fmt.Printf("// decode is the decoding table from GBK code to Unicode.\n")
fmt.Printf("// It is defined at http://encoding.spec.whatwg.org/index-gbk.txt\n")
fmt.Printf("var decode = [...]uint16{\n")
for i, v := range mapping {
if v != 0 {
fmt.Printf("\t%d: 0x%04X,\n", i, v)
}
}
fmt.Printf("}\n\n")
// Any run of at least separation continuous zero entries in the reverse map will
// be a separate encode table.
const separation = 1024
intervals := []interval(nil)
low, high := -1, -1
for i, v := range reverse {
if v == 0 {
continue
}
if low < 0 {
low = i
} else if i-high >= separation {
if high >= 0 {
intervals = append(intervals, interval{low, high})
}
low = i
}
high = i + 1
}
if high >= 0 {
intervals = append(intervals, interval{low, high})
}
sort.Sort(byDecreasingLength(intervals))
fmt.Printf("const numEncodeTables = %d\n\n", len(intervals))
fmt.Printf("// encodeX are the encoding tables from Unicode to GBK code,\n")
fmt.Printf("// sorted by decreasing length.\n")
for i, v := range intervals {
fmt.Printf("// encode%d: %5d entries for runes in [%5d, %5d).\n", i, v.len(), v.low, v.high)
}
fmt.Printf("\n")
for i, v := range intervals {
fmt.Printf("const encode%dLow, encode%dHigh = %d, %d\n\n", i, i, v.low, v.high)
fmt.Printf("var encode%d = [...]uint16{\n", i)
for j := v.low; j < v.high; j++ {
x := reverse[j]
if x == 0 {
continue
}
fmt.Printf("\t%d-%d: 0x%04X,\n", j, v.low, x)
}
fmt.Printf("}\n\n")
}
}
// interval is a half-open interval [low, high).
type interval struct {
low, high int
}
func (i interval) len() int { return i.high - i.low }
// byDecreasingLength sorts intervals by decreasing length.
type byDecreasingLength []interval
func (b byDecreasingLength) Len() int { return len(b) }
func (b byDecreasingLength) Less(i, j int) bool { return b[i].len() > b[j].len() }
func (b byDecreasingLength) Swap(i, j int) { b[i], b[j] = b[j], b[i] }

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,510 @@
This file was derived from
http://www.gutenberg.org/cache/epub/4650/pg4650.txt
--------
CANDIDE,
ou
L'OPTIMISME,
TRADUIT DE L'ALLEMAND
DE M. LE DOCTEUR RALPH,
AVEC LES ADDITIONS
QU'ON A TROUV<55>0‡7ES DANS LA POCHE DU DOCTEUR, LORSQU'IL MOURUT
<20>0†8 MINDEN, L'AN DE GR<47>0‡0CE 1759
1759
CHAPITRE I.
Comment Candide fut ¨¦lev¨¦ dans un beau ch<63>0‰9teau, et comment il fut
chass¨¦ d'icelui.
Il y avait en Vestphalie, dans le ch<63>0‰9teau de M. le baron de
Thunder-ten-tronckh, un jeune gar<61>0Š4on ¨¤ qui la nature avait donn¨¦
les moeurs les plus douces. Sa physionomie annon<6F>0Š4ait son <20>0‰9me.
Il avait le jugement assez droit, avec l'esprit le plus simple;
c'est, je crois, pour cette raison qu'on le nommait Candide. Les
anciens domestiques de la maison soup<75>0Š4onnaient qu'il ¨¦tait fils
de la soeur de monsieur le baron et d'un bon et honn¨ºte
gentilhomme du voisinage, que cette demoiselle ne voulut jamais
¨¦pouser parce qu'il n'avait pu prouver que soixante et onze
quartiers, et que le reste de son arbre g¨¦n¨¦alogique avait ¨¦t¨¦
perdu par l'injure du temps.
Monsieur le baron ¨¦tait un des plus puissants seigneurs de la
Westphalie, car son ch<63>0‰9teau avait une porte et des fen¨ºtres. Sa
grande salle m¨ºme ¨¦tait orn¨¦e d'une tapisserie. Tous les chiens
de ses basses-cours composaient une meute dans le besoin; ses
palefreniers ¨¦taient ses piqueurs; le vicaire du village ¨¦tait
son grand-aum<75>00nier. Ils l'appelaient tous monseigneur, et ils
riaient quand il fesait des contes.
Madame la baronne, qui pesait environ trois cent cinquante
livres, s'attirait par l¨¤ une tr¨¨s grande consid¨¦ration, et
fesait les honneurs de la maison avec une dignit¨¦ qui la rendait
encore plus respectable. Sa fille Cun¨¦gonde, <20>0‰9g¨¦e de dix-sept
ans, ¨¦tait haute en couleur, fra<72>0Š6che, grasse, app¨¦tissante. Le
fils du baron paraissait en tout digne de son p¨¨re. Le
pr¨¦cepteur Pangloss[1] ¨¦tait l'oracle de la maison, et le petit
Candide ¨¦coutait ses le<6C>0Š4ons avec toute la bonne foi de son <20>0‰9ge et
de son caract¨¨re.
[1] De _pan_, tout, et _glossa_, langue. B.
Pangloss enseignait la m¨¦taphysico-th¨¦ologo-cosmolonigologie. Il
prouvait admirablement qu'il n'y a point d'effet sans cause, et
que, dans ce meilleur des mondes possibles, le ch<63>0‰9teau de
monseigneur le baron ¨¦tait le plus beau des ch<63>0‰9teaux, et madame
la meilleure des baronnes possibles.
Il est d¨¦montr¨¦, disait-il, que les choses ne peuvent ¨ºtre
autrement; car tout ¨¦tant fait pour une fin, tout est
n¨¦cessairement pour la meilleure fin. Remarquez bien que les nez
ont ¨¦t¨¦ faits pour porter des lunettes; aussi avons-nous des
lunettes[2]. Les jambes sont visiblement institu¨¦es pour ¨ºtre
chauss¨¦es, et nous avons des chausses. Les pierres ont ¨¦t¨¦
form¨¦es pour ¨ºtre taill¨¦es et pour en faire des ch<63>0‰9teaux; aussi
monseigneur a un tr¨¨s beau ch<63>0‰9teau: le plus grand baron de la
province doit ¨ºtre le mieux log¨¦; et les cochons ¨¦tant faits pour
¨ºtre mang¨¦s, nous mangeons du porc toute l'ann¨¦e: par cons¨¦quent,
ceux qui ont avanc¨¦ que tout est bien ont dit une sottise; il
fallait dire que tout est au mieux.
[2] Voyez tome XXVII, page 528; et dans les _M¨¦langes_, ann¨¦e
1738, le chapitre XI de la troisi¨¨me partie des _<>0‡7l¨¦ments de la
philosophie de Newton_; et ann¨¦e 1768, le chapitre X des
_Singularit¨¦s de la nature_. B.
Candide ¨¦coutait attentivement, et croyait innocemment; car il
trouvait mademoiselle Cun¨¦gonde extr¨ºmement belle, quoiqu'il ne
pr<EFBFBD>0Š6t jamais la hardiesse de le lui dire. Il concluait qu'apr¨¨s
le bonheur d'¨ºtre n¨¦ baron de Thunder-ten-tronckh, le second
degr¨¦ de bonheur ¨¦tait d'¨ºtre mademoiselle Cun¨¦gonde; le
troisi¨¨me, de la voir tous les jours; et le quatri¨¨me, d'entendre
ma<EFBFBD>0Š6tre Pangloss, le plus grand philosophe de la province, et par
cons¨¦quent de toute la terre.
Un jour Cun¨¦gonde, en se promenant aupr¨¨s du ch<63>0‰9teau, dans le
petit bois qu'on appelait parc, vit entre des broussailles le
docteur Pangloss qui donnait une le<6C>0Š4on de physique exp¨¦rimentale
¨¤ la femme de chambre de sa m¨¨re, petite brune tr¨¨s jolie et tr¨¨s
docile. Comme mademoiselle Cun¨¦gonde avait beaucoup de
disposition pour les sciences, elle observa, sans souffler, les
exp¨¦riences r¨¦it¨¦r¨¦es dont elle fut t¨¦moin; elle vit clairement
la raison suffisante du docteur, les effets et les causes, et
s'en retourna tout agit¨¦e, toute pensive, toute remplie du d¨¦sir
d'¨ºtre savante, songeant qu'elle pourrait bien ¨ºtre la raison
suffisante du jeune Candide, qui pouvait aussi ¨ºtre la sienne.
Elle rencontra Candide en revenant au ch<63>0‰9teau, et rougit: Candide
rougit aussi . Elle lui dit bonjour d'une voix entrecoup¨¦e; et
Candide lui parla sans savoir ce qu'il disait. Le lendemain,
apr¨¨s le d<>0Š6ner, comme on sortait de table, Cun¨¦gonde et Candide
se trouv¨¨rent derri¨¨re un paravent; Cun¨¦gonde laissa tomber son
mouchoir, Candide le ramassa; elle lui prit innocemment la main;
le jeune homme baisa innocemment la main de la jeune demoiselle
avec une vivacit¨¦, une sensibilit¨¦, une gr<67>0‰9ce toute particuli¨¨re;
leurs bouches se rencontr¨¨rent, leurs yeux s'enflamm¨¨rent, leurs
genoux trembl¨¨rent, leurs mains s'¨¦gar¨¨rent. M. le baron de
Thunder-ten-tronckh passa aupr¨¨s du paravent, et voyant cette
cause et cet effet, chassa Candide du ch<63>0‰9teau ¨¤ grands coups de
pied dans le derri¨¨re. Cun¨¦gonde s'¨¦vanouit: elle fut soufflet¨¦e
par madame la baronne d¨¨s qu'elle fut revenue ¨¤ elle-m¨ºme; et
tout fut constern¨¦ dans le plus beau et le plus agr¨¦able des
ch<EFBFBD>0‰9teaux possibles.
CHAPITRE II
Ce que devint Candide parmi les Bulgares.
Candide, chass¨¦ du paradis terrestre, marcha longtemps sans
savoir o¨´, pleurant, levant les yeux au ciel, les tournant
souvent vers le plus beau des ch<63>0‰9teaux qui renfermait la plus
belle des baronnettes; il se coucha sans souper au milieu des
champs entre deux sillons; la neige tombait ¨¤ gros flocons.
Candide, tout transi, se tra<72>0Š6na le lendemain vers la ville
voisine, qui s'appelle _Valdberghoff-trarbk-dikdorff_, n'ayant
point d'argent, mourant de faim et de lassitude. Il s'arr¨ºta
tristement ¨¤ la porte d'un cabaret. Deux hommes habill¨¦s de bleu
le remarqu¨¨rent: Camarade, dit l'un, voil¨¤ un jeune homme tr¨¨s
bien fait, et qui a la taille requise; ils s'avanc¨¨rent vers
Candide et le pri¨¨rent ¨¤ d<>0Š6ner tr¨¨s civilement.--Messieurs, leur
dit Candide avec une modestie charmante, vous me faites beaucoup
d'honneur, mais je n'ai pas de quoi payer mon ¨¦cot.--Ah!
monsieur, lui dit un des bleus, les personnes de votre figure et
de votre m¨¦rite ne paient jamais rien: n'avez-vous pas cinq pieds
cinq pouces de haut?--Oui, messieurs, c'est ma taille, dit-il en
fesant la r¨¦v¨¦rence.--Ah! monsieur, mettez-vous ¨¤ table; non
seulement nous vous d¨¦fraierons, mais nous ne souffrirons jamais
qu'un homme comme vous manque d'argent; les hommes ne sont faits
que pour se secourir les uns les autres.--Vous avez raison, dit
Candide; c'est ce que M. Pangloss m'a toujours dit, et je vois
bien que tout est au mieux. On le prie d'accepter quelques ¨¦cus,
il les prend et veut faire son billet; on n'en veut point, on se
met ¨¤ table. N'aimez-vous pas tendrement?....--Oh! oui,
r¨¦pond-il, j'aime tendrement mademoiselle Cun¨¦gonde.--Non, dit
l'un de ces messieurs, nous vous demandons si vous n'aimez pas
tendrement le roi des Bulgares?--Point du tout, dit-il, car je ne
l'ai jamais vu.--Comment! c'est le plus charmant des rois, et il
faut boire ¨¤ sa sant¨¦.--Oh! tr¨¨s volontiers, messieurs. Et il
boit. C'en est assez, lui dit-on, vous voil¨¤ l'appui, le
soutien, le d¨¦fenseur, le h¨¦ros des Bulgares; votre fortune est
faite, et votre gloire est assur¨¦e. On lui met sur-le-champ les
fers aux pieds, et on le m¨¨ne au r¨¦giment. On le fait tourner ¨¤
droite, ¨¤ gauche, hausser la baguette, remettre la baguette,
coucher en joue, tirer, doubler le pas, et on lui donne trente
coups de b<>0‰9ton; le lendemain, il fait l'exercice un peu moins
mal, et il ne re<72>0Š4oit que vingt coups; le surlendemain, on ne lui
en donne que dix, et il est regard¨¦ par ses camarades comme un
prodige.
Candide, tout stup¨¦fait, ne d¨¦m¨ºlait pas encore trop bien comment
il ¨¦tait un h¨¦ros. Il s'avisa un beau jour de printemps de
s'aller promener, marchant tout droit devant lui, croyant que
c'¨¦tait un privil¨¨ge de l'esp¨¨ce humaine, comme de l'esp¨¨ce
animale, de se servir de ses jambes ¨¤ son plaisir. Il n'eut pas
fait deux lieues que voil¨¤ quatre autres h¨¦ros de six pieds qui
l'atteignent, qui le lient, qui le m¨¨nent dans un cachot. On lui
demanda juridiquement ce qu'il aimait le mieux d'¨ºtre fustig¨¦
trente-six fois par tout le r¨¦giment, ou de recevoir ¨¤-la-fois
douze balles de plomb dans la cervelle. Il eut beau dire que les
volont¨¦s sont libres, et qu'il ne voulait ni l'un ni l'autre, il
fallut faire un choix; il se d¨¦termina, en vertu du don de Dieu
qu'on nomme _libert¨¦_, ¨¤ passer trente-six fois par les
baguettes; il essuya deux promenades. Le r¨¦giment ¨¦tait compos¨¦
de deux mille hommes; cela lui composa quatre mille coups de
baguette, qui, depuis la nuque du cou jusqu'au cul, lui
d¨¦couvrirent les muscles et les nerfs. Comme on allait proc¨¦der
¨¤ la troisi¨¨me course, Candide, n'en pouvant plus, demanda en
gr<EFBFBD>0‰9ce qu'on voul<75>04t bien avoir la bont¨¦ de lui casser la t¨ºte; il
obtint cette faveur; on lui bande les yeux; on le fait mettre ¨¤
genoux. Le roi des Bulgares passe dans ce moment, s'informe du
crime du patient; et comme ce roi avait un grand g¨¦nie, il
comprit, par tout ce qu'il apprit de Candide, que c'¨¦tait un
jeune m¨¦taphysicien fort ignorant des choses de ce monde, et il
lui accorda sa gr<67>0‰9ce avec une cl¨¦mence qui sera lou¨¦e dans tous
les journaux et dans tous les si¨¨cles. Un brave chirurgien
gu¨¦rit Candide en trois semaines avec les ¨¦mollients enseign¨¦s
par Dioscoride. Il avait d¨¦j¨¤ un peu de peau et pouvait marcher,
quand le roi des Bulgares livra bataille au roi des Abares.
CHAPITRE III.
Comment Candide se sauva d'entre les Bulgares, et ce qu'il
devint.
Rien n'¨¦tait si beau, si leste, si brillant, si bien ordonn¨¦ que
les deux arm¨¦es. Les trompettes, les fifres, les hautbois, les
tambours, les canons; formaient une harmonie telle qu'il n'y en
eut jamais en enfer. Les canons renvers¨¨rent d'abord ¨¤ peu pr¨¨s
six mille hommes de chaque c<>00t¨¦; ensuite la mousqueterie <20>00ta du
meilleur des mondes environ neuf ¨¤ dix mille coquins qui en
infectaient la surface. La ba<62>0Š7onnette fut aussi la raison
suffisante de la mort de quelques milliers d'hommes. Le tout
pouvait bien se monter ¨¤ une trentaine de mille <20>0‰9mes. Candide,
qui tremblait comme un philosophe, se cacha du mieux qu'il put
pendant cette boucherie h¨¦ro<72>0Š7que.
Enfin, tandis que les deux rois fesaient chanter des _Te Deum_,
chacun dans son camp, il prit le parti d'aller raisonner ailleurs
des effets et des causes. Il passa par-dessus des tas de morts
et de mourants, et gagna d'abord un village voisin; il ¨¦tait en
cendres: c'¨¦tait un village abare que les Bulgares avaient br<62>04l¨¦,
selon les lois du droit public. Ici des vieillards cribl¨¦s de
coups regardaient mourir leurs femmes ¨¦gorg¨¦es, qui tenaient
leurs enfants ¨¤ leurs mamelles sanglantes; l¨¤ des filles
¨¦ventr¨¦es apr¨¨s avoir assouvi les besoins naturels de quelques
h¨¦ros, rendaient les derniers soupirs; d'autres ¨¤ demi br<62>04l¨¦es
criaient qu'on achev<65>0‰9t de leur donner la mort. Des cervelles
¨¦taient r¨¦pandues sur la terre ¨¤ c<>00t¨¦ de bras et de jambes
coup¨¦s.
Candide s'enfuit au plus vite dans un autre village: il
appartenait ¨¤ des Bulgares, et les h¨¦ros abares l'avaient trait¨¦
de m¨ºme. Candide, toujours marchant sur des membres palpitants
ou ¨¤ travers des ruines, arriva enfin hors du th¨¦<C2A8>0‰9tre de la
guerre, portant quelques petites provisions dans son bissac, et
n'oubliant jamais mademoiselle Cun¨¦gonde. Ses provisions lui
manqu¨¨rent quand il fut en Hollande; mais ayant entendu dire que
tout le monde ¨¦tait riche dans ce pays-l¨¤, et qu'on y ¨¦tait
chr¨¦tien, il ne douta pas qu'on ne le trait<69>0‰9t aussi bien qu'il
l'avait ¨¦t¨¦ dans le ch<63>0‰9teau de M. le baron, avant qu'il en e<>04t
¨¦t¨¦ chass¨¦ pour les beaux yeux de mademoiselle Cun¨¦gonde.
Il demanda l'aum<75>00ne ¨¤ plusieurs graves personnages, qui lui
r¨¦pondirent tous que, s'il continuait ¨¤ faire ce m¨¦tier, on
l'enfermerait dans une maison de correction pour lui apprendre ¨¤
vivre.
Il s'adressa ensuite ¨¤ un homme qui venait de parler tout seul
une heure de suite sur la charit¨¦ dans une grande assembl¨¦e. Cet
orateur le regardant de travers lui dit: Que venez-vous faire
ici? y ¨ºtes-vous pour la bonne cause? Il n'y a point d'effet sans
cause, r¨¦pondit modestement Candide; tout est encha<68>0Š6n¨¦
n¨¦cessairement et arrang¨¦ pour le mieux. Il a fallu que je fusse
chass¨¦ d'aupr¨¨s de mademoiselle Cun¨¦gonde, que j'aie pass¨¦ par
les baguettes, et il faut que je demande mon pain, jusqu'¨¤ ce que
je puisse en gagner; tout cela ne pouvait ¨ºtre autrement. Mon
ami, lui dit l'orateur, croyez-vous que le pape soit
l'antechrist? Je ne l'avais pas encore entendu dire, r¨¦pondit
Candide: mais qu'il le soit, ou qu'il ne le soit pas, je manque
de pain. Tu ne m¨¦rites pas d'en manger, dit l'autre: va, coquin,
va, mis¨¦rable, ne m'approche de ta vie. La femme de l'orateur
ayant mis la t¨ºte ¨¤ la fen¨ºtre, et avisant un homme qui doutait
que le pape f<>04t antechrist, lui r¨¦pandit sur le chef un
plein..... O ciel! ¨¤ quel exc¨¨s se porte le z¨¨le de la religion
dans les dames!
Un homme qui n'avait point ¨¦t¨¦ baptis¨¦, un bon anabaptiste, nomm¨¦
Jacques, vit la mani¨¨re cruelle et ignominieuse dont on traitait
ainsi un de ses fr¨¨res, un ¨ºtre ¨¤ deux pieds sans plumes, qui
avait une <20>0‰9me; il l'amena chez lui, le nettoya, lui donna du pain
et de la bi¨¨re, lui fit pr¨¦sent de deux florins, et voulut m¨ºme
lui apprendre ¨¤ travailler dans ses manufactures aux ¨¦toffes de
Perse qu'on fabrique en Hollande. Candide se prosternant presque
devant lui, s'¨¦criait: Ma<4D>0Š6tre Pangloss me l'avait bien dit que
tout est au mieux dans ce monde, car je suis infiniment plus
touch¨¦ de votre extr¨ºme g¨¦n¨¦rosit¨¦ que de la duret¨¦ de ce
monsieur ¨¤ manteau noir, et de madame son ¨¦pouse.
Le lendemain, en se promenant, il rencontra un gueux tout couvert
de pustules, les yeux morts, le bout du nez rong¨¦, la bouche de
travers, les dents noires, et parlant de la gorge, tourment¨¦
d'une toux violente, et crachant une dent ¨¤ chaque effort.
CHAPITRE IV.
Comment Candide rencontra son ancien ma<6D>0Š6tre de philosophie, le
docteur Pangloss, et ce qui en advint.
Candide, plus ¨¦mu encore de compassion que d'horreur, donna ¨¤ cet
¨¦pouvantable gueux les deux florins qu'il avait re<72>0Š4us de son
honn¨ºte anabaptiste Jacques. Le fant<6E>00me le regarda fixement,
versa des larmes, et sauta ¨¤ son cou. Candide effray¨¦ recule.
H¨¦las! dit le mis¨¦rable ¨¤ l'autre mis¨¦rable, ne reconnaissez-vous
plus votre cher Pangloss? Qu'entends-je? vous, mon cher ma<6D>0Š6tre!
vous, dans cet ¨¦tat horrible! quel malheur vous est-il donc
arriv¨¦? pourquoi n'¨ºtes-vous plus dans le plus beau des ch<63>0‰9teaux?
qu'est devenue mademoiselle Cun¨¦gonde, la perle des filles, le
chef-d'oeuvre de la nature? Je n'en peux plus, dit Pangloss.
Aussit<EFBFBD>00t Candide le mena dans l'¨¦table de l'anabaptiste, o¨´ il
lui fit manger un peu de pain; et quand Pangloss fut refait: Eh
bien! lui dit-il, Cun¨¦gonde? Elle est morte, reprit l'autre.
Candide s'¨¦vanouit ¨¤ ce mot: son ami rappela ses sens avec un peu
de mauvais vinaigre qui se trouva par hasard dans l'¨¦table.
Candide rouvre les yeux. Cun¨¦gonde est morte! Ah! meilleur des
mondes, o¨´ ¨ºtes-vous? Mais de quelle maladie est-elle morte? ne
serait-ce point de m'avoir vu chasser du beau ch<63>0‰9teau de monsieur
son p¨¨re ¨¤ grands coups de pied? Non, dit Pangloss, elle a ¨¦t¨¦
¨¦ventr¨¦e par des soldats bulgares, apr¨¨s avoir ¨¦t¨¦ viol¨¦e autant
qu'on peut l'¨ºtre; ils ont cass¨¦ la t¨ºte ¨¤ monsieur le baron qui
voulait la d¨¦fendre; madame la baronne a ¨¦t¨¦ coup¨¦e en morceaux;
mon pauvre pupille trait¨¦ pr¨¦cis¨¦ment comme sa soeur; et quant au
ch<EFBFBD>0‰9teau, il n'est pas rest¨¦ pierre sur pierre, pas une grange,
pas un mouton, pas un canard, pas un arbre; mais nous avons ¨¦t¨¦
bien veng¨¦s, car les Abares en ont fait autant dans une baronnie
voisine qui appartenait ¨¤ un seigneur bulgare.
A ce discours, Candide s'¨¦vanouit encore; mais revenu ¨¤ soi, et
ayant dit tout ce qu'il devait dire, il s'enquit de la cause et
de l'effet, et de la raison suffisante qui avait mis Pangloss
dans un si piteux ¨¦tat. H¨¦las! dit l'autre, c'est l'amour:
l'amour, le consolateur du genre humain, le conservateur de
l'univers, l'<27>0‰9me de tous les ¨ºtres sensibles, le tendre amour.
H¨¦las! dit Candide, je l'ai connu cet amour, ce souverain des
coeurs, cette <20>0‰9me de notre <20>0‰9me; il ne m'a jamais valu qu'un
baiser et vingt coups de pied au cul. Comment cette belle cause
a-t-elle pu produire en vous un effet si abominable?
Pangloss r¨¦pondit en ces termes: O mon cher Candide! vous avez
connu Paquette, cette jolie suivante de notre auguste baronne:
j'ai go<67>04t¨¦ dans ses bras les d¨¦lices du paradis, qui ont produit
ces tourments d'enfer dont vous me voyez d¨¦vor¨¦; elle en ¨¦tait
infect¨¦e, elle en est peut-¨ºtre morte. Paquette tenait ce
pr¨¦sent d'un cordelier tr¨¨s savant qui avait remont¨¦ ¨¤ la source,
car il l'avait eu d'une vieille comtesse, qui l'avait re<72>0Š4u d'un
capitaine de cavalerie, qui le devait ¨¤ une marquise, qui le
tenait d'un page, qui l'avait re<72>0Š4u d'un j¨¦suite, qui, ¨¦tant
novice, l'avait eu en droite ligne d'un des compagnons de
Christophe Colomb. Pour moi, je ne le donnerai ¨¤ personne, car
je me meurs.
O Pangloss! s'¨¦cria Candide, voil¨¤ une ¨¦trange g¨¦n¨¦alogie!
n'est-ce pas le diable qui en fut la souche? Point du tout,
r¨¦pliqua ce grand homme; c'¨¦tait une chose indispensable dans le
meilleur des mondes, un ingr¨¦dient n¨¦cessaire; car si Colomb
n'avait pas attrap¨¦ dans une <20>0Š6le de l'Am¨¦rique cette maladie[1]
qui empoisonne la source de la g¨¦n¨¦ration, qui souvent m¨ºme
emp¨ºche la g¨¦n¨¦ration, et qui est ¨¦videmment l'oppos¨¦ du grand
but de la nature, nous n'aurions ni le chocolat ni la cochenille;
il faut encore observer que jusqu'aujourd'hui, dans notre
continent, cette maladie nous est particuli¨¨re, comme la
controverse. Les Turcs, les Indiens, les Persans, les Chinois,
les Siamois, les Japonais, ne la connaissent pas encore; mais il
y a une raison suffisante pour qu'ils la connaissent ¨¤ leur tour
dans quelques si¨¨cles. En attendant elle a fait un merveilleux
progr¨¨s parmi nous, et surtout dans ces grandes arm¨¦es compos¨¦es
d'honn¨ºtes stipendiaires bien ¨¦lev¨¦s, qui d¨¦cident du destin des
¨¦tats; on peut assurer que, quand trente mille hommes combattent
en bataille rang¨¦e contre des troupes ¨¦gales en nombre, il y a
environ vingt mille v¨¦rol¨¦s de chaque c<>00t¨¦.
[1] Voyez tome XXXI, page 7. B.
Voil¨¤ qui est admirable, dit Candide; mais il faut vous faire
gu¨¦rir. Et comment le puis-je? dit Pangloss; je n'ai pas le sou,
mon ami, et dans toute l'¨¦tendue de ce globe on ne peut ni se
faire saigner, ni prendre un lavement sans payer, ou sans qu'il y
ait quelqu'un qui paie pour nous.
Ce dernier discours d¨¦termina Candide; il alla se jeter aux pieds
de son charitable anabaptiste Jacques, et lui fit une peinture si
touchante de l'¨¦tat o¨´ son ami ¨¦tait r¨¦duit, que le bon-homme
n'h¨¦sita pas ¨¤ recueillir le docteur Pangloss; il le fit gu¨¦rir ¨¤
ses d¨¦pens. Pangloss, dans la cure, ne perdit qu'un oeil et une
oreille. Il ¨¦crivait bien, et savait parfaitement
l'arithm¨¦tique. L'anabaptiste Jacques en fit son teneur de
livres. Au bout de deux mois, ¨¦tant oblig¨¦ d'aller ¨¤ Lisbonne
pour les affaires de son commerce, il mena dans son vaisseau ses
deux philosophes. Pangloss lui expliqua comment tout ¨¦tait on ne
peut mieux. Jacques n'¨¦tait pas de cet avis. Il faut bien,
disait-il, que les hommes aient un peu corrompu la nature, car
ils ne sont point n¨¦s loups, et ils sont devenus loups. Dieu ne
leur a donn¨¦ ni canons de vingt-quatre, ni ba<62>0Š7onnettes, et ils se
sont fait des ba<62>0Š7onnettes et des canons pour se d¨¦truire. Je
pourrais mettre en ligne de compte les banqueroutes, et la
justice qui s'empare des biens des banqueroutiers pour en
frustrer les cr¨¦anciers. Tout cela ¨¦tait indispensable,
r¨¦pliquait le docteur borgne, et les malheurs particuliers font
le bien g¨¦n¨¦ral; de sorte que plus il y a de malheurs
particuliers, et plus tout est bien. Tandis qu'il raisonnait,
l'air s'obscurcit, les vents souffl¨¨rent des quatre coins du
monde, et le vaisseau fut assailli de la plus horrible temp¨ºte, ¨¤
la vue du port de Lisbonne.
CHAPITRE V.
Temp¨ºte, naufrage, tremblement de terre, et ce qui advint du
docteur Pangloss, de Candide, et de l'anabaptiste Jacques.
La moiti¨¦ des passagers affaiblis, expirants de ces angoisses
inconcevables que le roulis d'un vaisseau porte dans les nerfs et
dans toutes les humeurs du corps agit¨¦es en sens contraires,
n'avait pas m¨ºme la force de s'inqui¨¦ter du danger. L'autre
moiti¨¦ jetait des cris et fesait des pri¨¨res; les voiles ¨¦taient
d¨¦chir¨¦es, les m<>0‰9ts bris¨¦s, le vaisseau entr'ouvert. Travaillait
qui pouvait, personne ne s'entendait, personne ne commandait.
L'anabaptiste aidait un peu ¨¤ la manoeuvre; il ¨¦tait sur le
tillac; un matelot furieux le frappe rudement et l'¨¦tend sur les
planches; mais du coup qu'il lui donna, il eut lui-m¨ºme une si
violente secousse, qu'il tomba hors du vaisseau, la t¨ºte la
premi¨¨re. Il restait suspendu et accroch¨¦ ¨¤ une partie de m<>0‰9t
rompu. Le bon Jacques court ¨¤ son secours, l'aide ¨¤ remonter, et
de l'effort qu'il fait, il est pr¨¦cipit¨¦ dans la mer ¨¤ la vue du
matelot, qui le laissa p¨¦rir sans daigner seulement le regarder.
Candide approche, voit son bienfaiteur qui repara<72>0Š6t un moment, et
qui est englouti pour jamais. Il veut se jeter apr¨¨s lui dans la
mer: le philosophe Pangloss l'en emp¨ºche, en lui prouvant que la
rade de Lisbonne avait ¨¦t¨¦ form¨¦e expr¨¨s pour que cet anabaptiste
s'y noy<6F>0‰9t. Tandis qu'il le prouvait _¨¤ priori_, le vaisseau
s'entr'ouvre, tout p¨¦rit ¨¤ la r¨¦serve de Pangloss, de Candide, et
de ce brutal de matelot qui avait noy¨¦ le vertueux anabaptiste;
le coquin nagea heureusement jusqu'au rivage, o¨´ Pangloss et
Candide furent port¨¦s sur une planche.
Quand ils furent revenus un peu ¨¤ eux, ils march¨¨rent vers
Lisbonne; il leur restait quelque argent, avec lequel ils
esp¨¦raient se sauver de la faim apr¨¨s avoir ¨¦chapp¨¦ ¨¤ la temp¨ºte.
A peine ont-ils mis le pied dans la ville, en pleurant la mort de
leur bienfaiteur, qu'ils sentent la terre trembler sous leurs
pas[1]; la mer s'¨¦l¨¨ve en bouillonnant dans le port, et brise les
vaisseaux qui sont ¨¤ l'ancre. Des tourbillons de flammes et de
cendres couvrent les rues et les places publiques; les maisons
s'¨¦croulent, les toits sont renvers¨¦s sur les fondements, et les
fondements se dispersent; trente mille habitants de tout <20>0‰9ge et
de tout sexe sont ¨¦cras¨¦s sous des ruines. Le matelot disait en
sifflant et en jurant: il y aura quelque chose ¨¤ gagner ici.
Quelle peut ¨ºtre la raison suffisante de ce ph¨¦nom¨¨ne? disait
Pangloss. Voici le dernier jour du monde! s'¨¦criait Candide.
Le matelot court incontinent au milieu des d¨¦bris, affronte la
mort pour trouver de l'argent, en trouve, s'en empare, s'enivre,
et ayant cuv¨¦ son vin, ach¨¨te les faveurs de la premi¨¨re fille de
bonne volont¨¦ qu'il rencontre sur les ruines des maisons
d¨¦truites, et au milieu des mourants et des morts. Pangloss le
tirait cependant par la manche: Mon ami, lui disait-il, cela
n'est pas bien, vous manquez ¨¤ la raison universelle, vous prenez
mal votre temps. T¨ºte et sang, r¨¦pondit l'autre, je suis matelot
et n¨¦ ¨¤ Batavia; j'ai march¨¦ quatre fois sur le crucifix dans
quatre voyages au Japon[2]; tu as bien trouv¨¦ ton homme avec ta
raison universelle!
[1] Le tremblement de terre de Lisbonne est du 1er novembre 1755.
B.
[2] Voyez tome XVIII, page 470. B.
Quelques ¨¦clats de pierre avaient bless¨¦ Candide; il ¨¦tait ¨¦tendu
dans la rue et couvert de d¨¦bris. Il disait ¨¤ Pangloss: H¨¦las!
procure-moi un peu de vin et d'huile; je me meurs. Ce
tremblement de terre n'est pas une chose nouvelle, r¨¦pondit
Pangloss; la ville de Lima ¨¦prouva les m¨ºmes secousses en
Am¨¦rique l'ann¨¦e pass¨¦e; m¨ºmes causes, m¨ºmes effets; il y a
certainement une tra<72>0Š6n¨¦e de soufre sous terre depuis Lima jusqu'¨¤
Lisbonne. Rien n'est plus probable, dit Candide; mais, pour
Dieu, un peu d'huile et de vin. Comment probable? r¨¦pliqua le
philosophe, je soutiens que la chose est d¨¦montr¨¦e. Candide
perdit connaissance, et Pangloss lui apporta un peu d'eau d'une
fontaine voisine.
Le lendemain, ayant trouv¨¦ quelques provisions de bouche en se
glissant ¨¤ travers des d¨¦combres, ils r¨¦par¨¨rent un peu leurs
forces. Ensuite ils travaill¨¨rent comme les autres ¨¤ soulager
les habitants ¨¦chapp¨¦s ¨¤ la mort. Quelques citoyens, secourus
par eux, leur donn¨¨rent un aussi bon d<>0Š6ner qu'on le pouvait dans
un tel d¨¦sastre: il est vrai que le repas ¨¦tait triste; les
convives arrosaient leur pain de leurs larmes; mais Pangloss les
consola, en les assurant que les choses ne pouvaient ¨ºtre
autrement: Car, dit-il, tout ceci est ce qu'il y a de mieux; car
s'il y a un volcan ¨¤ Lisbonne, il ne pouvait ¨ºtre ailleurs; car
il est impossible que les choses ne soient pas o¨´ elles sont, car
tout est bien.
Un petit homme noir, familier de l'inquisition, lequel ¨¦tait ¨¤
c<EFBFBD>00t¨¦ de lui, prit poliment la parole et dit: Apparemment que
monsieur ne croit pas au p¨¦ch¨¦ originel; car si tout est au
mieux, il n'y a donc eu ni chute ni punition.
Je demande tr¨¨s humblement pardon ¨¤ votre excellence, r¨¦pondit
Pangloss encore plus poliment, car la chute de l'homme et la
mal¨¦diction entraient n¨¦cessairement dans le meilleur des mondes
possibles. Monsieur ne croit donc pas ¨¤ la libert¨¦? dit le
familier. Votre excellence m'excusera, dit Pangloss; la libert¨¦
peut subsister avec la n¨¦cessit¨¦ absolue; car il ¨¦tait n¨¦cessaire
que nous fussions libres; car enfin la volont¨¦ d¨¦termin¨¦e......
Pangloss ¨¦tait au milieu de sa phrase, quand Je familier fit un
signe de t¨ºte ¨¤ son estafier qui lui servait ¨¤ boire du vin de
Porto ou d'Oporto.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,510 @@
This file was derived from
http://www.gutenberg.org/cache/epub/4650/pg4650.txt
--------
CANDIDE,
ou
L'OPTIMISME,
TRADUIT DE L'ALLEMAND
DE M. LE DOCTEUR RALPH,
AVEC LES ADDITIONS
QU'ON A TROUVÉES DANS LA POCHE DU DOCTEUR, LORSQU'IL MOURUT
À MINDEN, L'AN DE GRÂCE 1759
1759
CHAPITRE I.
Comment Candide fut élevé dans un beau château, et comment il fut
chassé d'icelui.
Il y avait en Vestphalie, dans le château de M. le baron de
Thunder-ten-tronckh, un jeune garçon à qui la nature avait donné
les moeurs les plus douces. Sa physionomie annonçait son âme.
Il avait le jugement assez droit, avec l'esprit le plus simple;
c'est, je crois, pour cette raison qu'on le nommait Candide. Les
anciens domestiques de la maison soupçonnaient qu'il était fils
de la soeur de monsieur le baron et d'un bon et honnête
gentilhomme du voisinage, que cette demoiselle ne voulut jamais
épouser parce qu'il n'avait pu prouver que soixante et onze
quartiers, et que le reste de son arbre généalogique avait été
perdu par l'injure du temps.
Monsieur le baron était un des plus puissants seigneurs de la
Westphalie, car son château avait une porte et des fenêtres. Sa
grande salle même était ornée d'une tapisserie. Tous les chiens
de ses basses-cours composaient une meute dans le besoin; ses
palefreniers étaient ses piqueurs; le vicaire du village était
son grand-aumônier. Ils l'appelaient tous monseigneur, et ils
riaient quand il fesait des contes.
Madame la baronne, qui pesait environ trois cent cinquante
livres, s'attirait par là une très grande considération, et
fesait les honneurs de la maison avec une dignité qui la rendait
encore plus respectable. Sa fille Cunégonde, âgée de dix-sept
ans, était haute en couleur, fraîche, grasse, appétissante. Le
fils du baron paraissait en tout digne de son père. Le
précepteur Pangloss[1] était l'oracle de la maison, et le petit
Candide écoutait ses leçons avec toute la bonne foi de son âge et
de son caractère.
[1] De _pan_, tout, et _glossa_, langue. B.
Pangloss enseignait la métaphysico-théologo-cosmolonigologie. Il
prouvait admirablement qu'il n'y a point d'effet sans cause, et
que, dans ce meilleur des mondes possibles, le château de
monseigneur le baron était le plus beau des châteaux, et madame
la meilleure des baronnes possibles.
Il est démontré, disait-il, que les choses ne peuvent être
autrement; car tout étant fait pour une fin, tout est
nécessairement pour la meilleure fin. Remarquez bien que les nez
ont été faits pour porter des lunettes; aussi avons-nous des
lunettes[2]. Les jambes sont visiblement instituées pour être
chaussées, et nous avons des chausses. Les pierres ont été
formées pour être taillées et pour en faire des châteaux; aussi
monseigneur a un très beau château: le plus grand baron de la
province doit être le mieux logé; et les cochons étant faits pour
être mangés, nous mangeons du porc toute l'année: par conséquent,
ceux qui ont avancé que tout est bien ont dit une sottise; il
fallait dire que tout est au mieux.
[2] Voyez tome XXVII, page 528; et dans les _Mélanges_, année
1738, le chapitre XI de la troisième partie des _Éléments de la
philosophie de Newton_; et année 1768, le chapitre X des
_Singularités de la nature_. B.
Candide écoutait attentivement, et croyait innocemment; car il
trouvait mademoiselle Cunégonde extrêmement belle, quoiqu'il ne
prît jamais la hardiesse de le lui dire. Il concluait qu'après
le bonheur d'être né baron de Thunder-ten-tronckh, le second
degré de bonheur était d'être mademoiselle Cunégonde; le
troisième, de la voir tous les jours; et le quatrième, d'entendre
maître Pangloss, le plus grand philosophe de la province, et par
conséquent de toute la terre.
Un jour Cunégonde, en se promenant auprès du château, dans le
petit bois qu'on appelait parc, vit entre des broussailles le
docteur Pangloss qui donnait une leçon de physique expérimentale
à la femme de chambre de sa mère, petite brune très jolie et très
docile. Comme mademoiselle Cunégonde avait beaucoup de
disposition pour les sciences, elle observa, sans souffler, les
expériences réitérées dont elle fut témoin; elle vit clairement
la raison suffisante du docteur, les effets et les causes, et
s'en retourna tout agitée, toute pensive, toute remplie du désir
d'être savante, songeant qu'elle pourrait bien être la raison
suffisante du jeune Candide, qui pouvait aussi être la sienne.
Elle rencontra Candide en revenant au château, et rougit: Candide
rougit aussi . Elle lui dit bonjour d'une voix entrecoupée; et
Candide lui parla sans savoir ce qu'il disait. Le lendemain,
après le dîner, comme on sortait de table, Cunégonde et Candide
se trouvèrent derrière un paravent; Cunégonde laissa tomber son
mouchoir, Candide le ramassa; elle lui prit innocemment la main;
le jeune homme baisa innocemment la main de la jeune demoiselle
avec une vivacité, une sensibilité, une grâce toute particulière;
leurs bouches se rencontrèrent, leurs yeux s'enflammèrent, leurs
genoux tremblèrent, leurs mains s'égarèrent. M. le baron de
Thunder-ten-tronckh passa auprès du paravent, et voyant cette
cause et cet effet, chassa Candide du château à grands coups de
pied dans le derrière. Cunégonde s'évanouit: elle fut souffletée
par madame la baronne dès qu'elle fut revenue à elle-même; et
tout fut consterné dans le plus beau et le plus agréable des
châteaux possibles.
CHAPITRE II
Ce que devint Candide parmi les Bulgares.
Candide, chassé du paradis terrestre, marcha longtemps sans
savoir où, pleurant, levant les yeux au ciel, les tournant
souvent vers le plus beau des châteaux qui renfermait la plus
belle des baronnettes; il se coucha sans souper au milieu des
champs entre deux sillons; la neige tombait à gros flocons.
Candide, tout transi, se traîna le lendemain vers la ville
voisine, qui s'appelle _Valdberghoff-trarbk-dikdorff_, n'ayant
point d'argent, mourant de faim et de lassitude. Il s'arrêta
tristement à la porte d'un cabaret. Deux hommes habillés de bleu
le remarquèrent: Camarade, dit l'un, voilà un jeune homme très
bien fait, et qui a la taille requise; ils s'avancèrent vers
Candide et le prièrent à dîner très civilement.--Messieurs, leur
dit Candide avec une modestie charmante, vous me faites beaucoup
d'honneur, mais je n'ai pas de quoi payer mon écot.--Ah!
monsieur, lui dit un des bleus, les personnes de votre figure et
de votre mérite ne paient jamais rien: n'avez-vous pas cinq pieds
cinq pouces de haut?--Oui, messieurs, c'est ma taille, dit-il en
fesant la révérence.--Ah! monsieur, mettez-vous à table; non
seulement nous vous défraierons, mais nous ne souffrirons jamais
qu'un homme comme vous manque d'argent; les hommes ne sont faits
que pour se secourir les uns les autres.--Vous avez raison, dit
Candide; c'est ce que M. Pangloss m'a toujours dit, et je vois
bien que tout est au mieux. On le prie d'accepter quelques écus,
il les prend et veut faire son billet; on n'en veut point, on se
met à table. N'aimez-vous pas tendrement?....--Oh! oui,
répond-il, j'aime tendrement mademoiselle Cunégonde.--Non, dit
l'un de ces messieurs, nous vous demandons si vous n'aimez pas
tendrement le roi des Bulgares?--Point du tout, dit-il, car je ne
l'ai jamais vu.--Comment! c'est le plus charmant des rois, et il
faut boire à sa santé.--Oh! très volontiers, messieurs. Et il
boit. C'en est assez, lui dit-on, vous voilà l'appui, le
soutien, le défenseur, le héros des Bulgares; votre fortune est
faite, et votre gloire est assurée. On lui met sur-le-champ les
fers aux pieds, et on le mène au régiment. On le fait tourner à
droite, à gauche, hausser la baguette, remettre la baguette,
coucher en joue, tirer, doubler le pas, et on lui donne trente
coups de bâton; le lendemain, il fait l'exercice un peu moins
mal, et il ne reçoit que vingt coups; le surlendemain, on ne lui
en donne que dix, et il est regardé par ses camarades comme un
prodige.
Candide, tout stupéfait, ne démêlait pas encore trop bien comment
il était un héros. Il s'avisa un beau jour de printemps de
s'aller promener, marchant tout droit devant lui, croyant que
c'était un privilège de l'espèce humaine, comme de l'espèce
animale, de se servir de ses jambes à son plaisir. Il n'eut pas
fait deux lieues que voilà quatre autres héros de six pieds qui
l'atteignent, qui le lient, qui le mènent dans un cachot. On lui
demanda juridiquement ce qu'il aimait le mieux d'être fustigé
trente-six fois par tout le régiment, ou de recevoir à-la-fois
douze balles de plomb dans la cervelle. Il eut beau dire que les
volontés sont libres, et qu'il ne voulait ni l'un ni l'autre, il
fallut faire un choix; il se détermina, en vertu du don de Dieu
qu'on nomme _liberté_, à passer trente-six fois par les
baguettes; il essuya deux promenades. Le régiment était composé
de deux mille hommes; cela lui composa quatre mille coups de
baguette, qui, depuis la nuque du cou jusqu'au cul, lui
découvrirent les muscles et les nerfs. Comme on allait procéder
à la troisième course, Candide, n'en pouvant plus, demanda en
grâce qu'on voulût bien avoir la bonté de lui casser la tête; il
obtint cette faveur; on lui bande les yeux; on le fait mettre à
genoux. Le roi des Bulgares passe dans ce moment, s'informe du
crime du patient; et comme ce roi avait un grand génie, il
comprit, par tout ce qu'il apprit de Candide, que c'était un
jeune métaphysicien fort ignorant des choses de ce monde, et il
lui accorda sa grâce avec une clémence qui sera louée dans tous
les journaux et dans tous les siècles. Un brave chirurgien
guérit Candide en trois semaines avec les émollients enseignés
par Dioscoride. Il avait déjà un peu de peau et pouvait marcher,
quand le roi des Bulgares livra bataille au roi des Abares.
CHAPITRE III.
Comment Candide se sauva d'entre les Bulgares, et ce qu'il
devint.
Rien n'était si beau, si leste, si brillant, si bien ordonné que
les deux armées. Les trompettes, les fifres, les hautbois, les
tambours, les canons; formaient une harmonie telle qu'il n'y en
eut jamais en enfer. Les canons renversèrent d'abord à peu près
six mille hommes de chaque côté; ensuite la mousqueterie ôta du
meilleur des mondes environ neuf à dix mille coquins qui en
infectaient la surface. La baïonnette fut aussi la raison
suffisante de la mort de quelques milliers d'hommes. Le tout
pouvait bien se monter à une trentaine de mille âmes. Candide,
qui tremblait comme un philosophe, se cacha du mieux qu'il put
pendant cette boucherie héroïque.
Enfin, tandis que les deux rois fesaient chanter des _Te Deum_,
chacun dans son camp, il prit le parti d'aller raisonner ailleurs
des effets et des causes. Il passa par-dessus des tas de morts
et de mourants, et gagna d'abord un village voisin; il était en
cendres: c'était un village abare que les Bulgares avaient brûlé,
selon les lois du droit public. Ici des vieillards criblés de
coups regardaient mourir leurs femmes égorgées, qui tenaient
leurs enfants à leurs mamelles sanglantes; là des filles
éventrées après avoir assouvi les besoins naturels de quelques
héros, rendaient les derniers soupirs; d'autres à demi brûlées
criaient qu'on achevât de leur donner la mort. Des cervelles
étaient répandues sur la terre à côté de bras et de jambes
coupés.
Candide s'enfuit au plus vite dans un autre village: il
appartenait à des Bulgares, et les héros abares l'avaient traité
de même. Candide, toujours marchant sur des membres palpitants
ou à travers des ruines, arriva enfin hors du théâtre de la
guerre, portant quelques petites provisions dans son bissac, et
n'oubliant jamais mademoiselle Cunégonde. Ses provisions lui
manquèrent quand il fut en Hollande; mais ayant entendu dire que
tout le monde était riche dans ce pays-là, et qu'on y était
chrétien, il ne douta pas qu'on ne le traitât aussi bien qu'il
l'avait été dans le château de M. le baron, avant qu'il en eût
été chassé pour les beaux yeux de mademoiselle Cunégonde.
Il demanda l'aumône à plusieurs graves personnages, qui lui
répondirent tous que, s'il continuait à faire ce métier, on
l'enfermerait dans une maison de correction pour lui apprendre à
vivre.
Il s'adressa ensuite à un homme qui venait de parler tout seul
une heure de suite sur la charité dans une grande assemblée. Cet
orateur le regardant de travers lui dit: Que venez-vous faire
ici? y êtes-vous pour la bonne cause? Il n'y a point d'effet sans
cause, répondit modestement Candide; tout est enchaîné
nécessairement et arrangé pour le mieux. Il a fallu que je fusse
chassé d'auprès de mademoiselle Cunégonde, que j'aie passé par
les baguettes, et il faut que je demande mon pain, jusqu'à ce que
je puisse en gagner; tout cela ne pouvait être autrement. Mon
ami, lui dit l'orateur, croyez-vous que le pape soit
l'antechrist? Je ne l'avais pas encore entendu dire, répondit
Candide: mais qu'il le soit, ou qu'il ne le soit pas, je manque
de pain. Tu ne mérites pas d'en manger, dit l'autre: va, coquin,
va, misérable, ne m'approche de ta vie. La femme de l'orateur
ayant mis la tête à la fenêtre, et avisant un homme qui doutait
que le pape fût antechrist, lui répandit sur le chef un
plein..... O ciel! à quel excès se porte le zèle de la religion
dans les dames!
Un homme qui n'avait point été baptisé, un bon anabaptiste, nommé
Jacques, vit la manière cruelle et ignominieuse dont on traitait
ainsi un de ses frères, un être à deux pieds sans plumes, qui
avait une âme; il l'amena chez lui, le nettoya, lui donna du pain
et de la bière, lui fit présent de deux florins, et voulut même
lui apprendre à travailler dans ses manufactures aux étoffes de
Perse qu'on fabrique en Hollande. Candide se prosternant presque
devant lui, s'écriait: Maître Pangloss me l'avait bien dit que
tout est au mieux dans ce monde, car je suis infiniment plus
touché de votre extrême générosité que de la dureté de ce
monsieur à manteau noir, et de madame son épouse.
Le lendemain, en se promenant, il rencontra un gueux tout couvert
de pustules, les yeux morts, le bout du nez rongé, la bouche de
travers, les dents noires, et parlant de la gorge, tourmenté
d'une toux violente, et crachant une dent à chaque effort.
CHAPITRE IV.
Comment Candide rencontra son ancien maître de philosophie, le
docteur Pangloss, et ce qui en advint.
Candide, plus ému encore de compassion que d'horreur, donna à cet
épouvantable gueux les deux florins qu'il avait reçus de son
honnête anabaptiste Jacques. Le fantôme le regarda fixement,
versa des larmes, et sauta à son cou. Candide effrayé recule.
Hélas! dit le misérable à l'autre misérable, ne reconnaissez-vous
plus votre cher Pangloss? Qu'entends-je? vous, mon cher maître!
vous, dans cet état horrible! quel malheur vous est-il donc
arrivé? pourquoi n'êtes-vous plus dans le plus beau des châteaux?
qu'est devenue mademoiselle Cunégonde, la perle des filles, le
chef-d'oeuvre de la nature? Je n'en peux plus, dit Pangloss.
Aussitôt Candide le mena dans l'étable de l'anabaptiste, où il
lui fit manger un peu de pain; et quand Pangloss fut refait: Eh
bien! lui dit-il, Cunégonde? Elle est morte, reprit l'autre.
Candide s'évanouit à ce mot: son ami rappela ses sens avec un peu
de mauvais vinaigre qui se trouva par hasard dans l'étable.
Candide rouvre les yeux. Cunégonde est morte! Ah! meilleur des
mondes, où êtes-vous? Mais de quelle maladie est-elle morte? ne
serait-ce point de m'avoir vu chasser du beau château de monsieur
son père à grands coups de pied? Non, dit Pangloss, elle a été
éventrée par des soldats bulgares, après avoir été violée autant
qu'on peut l'être; ils ont cassé la tête à monsieur le baron qui
voulait la défendre; madame la baronne a été coupée en morceaux;
mon pauvre pupille traité précisément comme sa soeur; et quant au
château, il n'est pas resté pierre sur pierre, pas une grange,
pas un mouton, pas un canard, pas un arbre; mais nous avons été
bien vengés, car les Abares en ont fait autant dans une baronnie
voisine qui appartenait à un seigneur bulgare.
A ce discours, Candide s'évanouit encore; mais revenu à soi, et
ayant dit tout ce qu'il devait dire, il s'enquit de la cause et
de l'effet, et de la raison suffisante qui avait mis Pangloss
dans un si piteux état. Hélas! dit l'autre, c'est l'amour:
l'amour, le consolateur du genre humain, le conservateur de
l'univers, l'âme de tous les êtres sensibles, le tendre amour.
Hélas! dit Candide, je l'ai connu cet amour, ce souverain des
coeurs, cette âme de notre âme; il ne m'a jamais valu qu'un
baiser et vingt coups de pied au cul. Comment cette belle cause
a-t-elle pu produire en vous un effet si abominable?
Pangloss répondit en ces termes: O mon cher Candide! vous avez
connu Paquette, cette jolie suivante de notre auguste baronne:
j'ai goûté dans ses bras les délices du paradis, qui ont produit
ces tourments d'enfer dont vous me voyez dévoré; elle en était
infectée, elle en est peut-être morte. Paquette tenait ce
présent d'un cordelier très savant qui avait remonté à la source,
car il l'avait eu d'une vieille comtesse, qui l'avait reçu d'un
capitaine de cavalerie, qui le devait à une marquise, qui le
tenait d'un page, qui l'avait reçu d'un jésuite, qui, étant
novice, l'avait eu en droite ligne d'un des compagnons de
Christophe Colomb. Pour moi, je ne le donnerai à personne, car
je me meurs.
O Pangloss! s'écria Candide, voilà une étrange généalogie!
n'est-ce pas le diable qui en fut la souche? Point du tout,
répliqua ce grand homme; c'était une chose indispensable dans le
meilleur des mondes, un ingrédient nécessaire; car si Colomb
n'avait pas attrapé dans une île de l'Amérique cette maladie[1]
qui empoisonne la source de la génération, qui souvent même
empêche la génération, et qui est évidemment l'opposé du grand
but de la nature, nous n'aurions ni le chocolat ni la cochenille;
il faut encore observer que jusqu'aujourd'hui, dans notre
continent, cette maladie nous est particulière, comme la
controverse. Les Turcs, les Indiens, les Persans, les Chinois,
les Siamois, les Japonais, ne la connaissent pas encore; mais il
y a une raison suffisante pour qu'ils la connaissent à leur tour
dans quelques siècles. En attendant elle a fait un merveilleux
progrès parmi nous, et surtout dans ces grandes armées composées
d'honnêtes stipendiaires bien élevés, qui décident du destin des
états; on peut assurer que, quand trente mille hommes combattent
en bataille rangée contre des troupes égales en nombre, il y a
environ vingt mille vérolés de chaque côté.
[1] Voyez tome XXXI, page 7. B.
Voilà qui est admirable, dit Candide; mais il faut vous faire
guérir. Et comment le puis-je? dit Pangloss; je n'ai pas le sou,
mon ami, et dans toute l'étendue de ce globe on ne peut ni se
faire saigner, ni prendre un lavement sans payer, ou sans qu'il y
ait quelqu'un qui paie pour nous.
Ce dernier discours détermina Candide; il alla se jeter aux pieds
de son charitable anabaptiste Jacques, et lui fit une peinture si
touchante de l'état où son ami était réduit, que le bon-homme
n'hésita pas à recueillir le docteur Pangloss; il le fit guérir à
ses dépens. Pangloss, dans la cure, ne perdit qu'un oeil et une
oreille. Il écrivait bien, et savait parfaitement
l'arithmétique. L'anabaptiste Jacques en fit son teneur de
livres. Au bout de deux mois, étant obligé d'aller à Lisbonne
pour les affaires de son commerce, il mena dans son vaisseau ses
deux philosophes. Pangloss lui expliqua comment tout était on ne
peut mieux. Jacques n'était pas de cet avis. Il faut bien,
disait-il, que les hommes aient un peu corrompu la nature, car
ils ne sont point nés loups, et ils sont devenus loups. Dieu ne
leur a donné ni canons de vingt-quatre, ni baïonnettes, et ils se
sont fait des baïonnettes et des canons pour se détruire. Je
pourrais mettre en ligne de compte les banqueroutes, et la
justice qui s'empare des biens des banqueroutiers pour en
frustrer les créanciers. Tout cela était indispensable,
répliquait le docteur borgne, et les malheurs particuliers font
le bien général; de sorte que plus il y a de malheurs
particuliers, et plus tout est bien. Tandis qu'il raisonnait,
l'air s'obscurcit, les vents soufflèrent des quatre coins du
monde, et le vaisseau fut assailli de la plus horrible tempête, à
la vue du port de Lisbonne.
CHAPITRE V.
Tempête, naufrage, tremblement de terre, et ce qui advint du
docteur Pangloss, de Candide, et de l'anabaptiste Jacques.
La moitié des passagers affaiblis, expirants de ces angoisses
inconcevables que le roulis d'un vaisseau porte dans les nerfs et
dans toutes les humeurs du corps agitées en sens contraires,
n'avait pas même la force de s'inquiéter du danger. L'autre
moitié jetait des cris et fesait des prières; les voiles étaient
déchirées, les mâts brisés, le vaisseau entr'ouvert. Travaillait
qui pouvait, personne ne s'entendait, personne ne commandait.
L'anabaptiste aidait un peu à la manoeuvre; il était sur le
tillac; un matelot furieux le frappe rudement et l'étend sur les
planches; mais du coup qu'il lui donna, il eut lui-même une si
violente secousse, qu'il tomba hors du vaisseau, la tête la
première. Il restait suspendu et accroché à une partie de mât
rompu. Le bon Jacques court à son secours, l'aide à remonter, et
de l'effort qu'il fait, il est précipité dans la mer à la vue du
matelot, qui le laissa périr sans daigner seulement le regarder.
Candide approche, voit son bienfaiteur qui reparaît un moment, et
qui est englouti pour jamais. Il veut se jeter après lui dans la
mer: le philosophe Pangloss l'en empêche, en lui prouvant que la
rade de Lisbonne avait été formée exprès pour que cet anabaptiste
s'y noyât. Tandis qu'il le prouvait _à priori_, le vaisseau
s'entr'ouvre, tout périt à la réserve de Pangloss, de Candide, et
de ce brutal de matelot qui avait noyé le vertueux anabaptiste;
le coquin nagea heureusement jusqu'au rivage, où Pangloss et
Candide furent portés sur une planche.
Quand ils furent revenus un peu à eux, ils marchèrent vers
Lisbonne; il leur restait quelque argent, avec lequel ils
espéraient se sauver de la faim après avoir échappé à la tempête.
A peine ont-ils mis le pied dans la ville, en pleurant la mort de
leur bienfaiteur, qu'ils sentent la terre trembler sous leurs
pas[1]; la mer s'élève en bouillonnant dans le port, et brise les
vaisseaux qui sont à l'ancre. Des tourbillons de flammes et de
cendres couvrent les rues et les places publiques; les maisons
s'écroulent, les toits sont renversés sur les fondements, et les
fondements se dispersent; trente mille habitants de tout âge et
de tout sexe sont écrasés sous des ruines. Le matelot disait en
sifflant et en jurant: il y aura quelque chose à gagner ici.
Quelle peut être la raison suffisante de ce phénomène? disait
Pangloss. Voici le dernier jour du monde! s'écriait Candide.
Le matelot court incontinent au milieu des débris, affronte la
mort pour trouver de l'argent, en trouve, s'en empare, s'enivre,
et ayant cuvé son vin, achète les faveurs de la première fille de
bonne volonté qu'il rencontre sur les ruines des maisons
détruites, et au milieu des mourants et des morts. Pangloss le
tirait cependant par la manche: Mon ami, lui disait-il, cela
n'est pas bien, vous manquez à la raison universelle, vous prenez
mal votre temps. Tête et sang, répondit l'autre, je suis matelot
et né à Batavia; j'ai marché quatre fois sur le crucifix dans
quatre voyages au Japon[2]; tu as bien trouvé ton homme avec ta
raison universelle!
[1] Le tremblement de terre de Lisbonne est du 1er novembre 1755.
B.
[2] Voyez tome XVIII, page 470. B.
Quelques éclats de pierre avaient blessé Candide; il était étendu
dans la rue et couvert de débris. Il disait à Pangloss: Hélas!
procure-moi un peu de vin et d'huile; je me meurs. Ce
tremblement de terre n'est pas une chose nouvelle, répondit
Pangloss; la ville de Lima éprouva les mêmes secousses en
Amérique l'année passée; mêmes causes, mêmes effets; il y a
certainement une traînée de soufre sous terre depuis Lima jusqu'à
Lisbonne. Rien n'est plus probable, dit Candide; mais, pour
Dieu, un peu d'huile et de vin. Comment probable? répliqua le
philosophe, je soutiens que la chose est démontrée. Candide
perdit connaissance, et Pangloss lui apporta un peu d'eau d'une
fontaine voisine.
Le lendemain, ayant trouvé quelques provisions de bouche en se
glissant à travers des décombres, ils réparèrent un peu leurs
forces. Ensuite ils travaillèrent comme les autres à soulager
les habitants échappés à la mort. Quelques citoyens, secourus
par eux, leur donnèrent un aussi bon dîner qu'on le pouvait dans
un tel désastre: il est vrai que le repas était triste; les
convives arrosaient leur pain de leurs larmes; mais Pangloss les
consola, en les assurant que les choses ne pouvaient être
autrement: Car, dit-il, tout ceci est ce qu'il y a de mieux; car
s'il y a un volcan à Lisbonne, il ne pouvait être ailleurs; car
il est impossible que les choses ne soient pas où elles sont, car
tout est bien.
Un petit homme noir, familier de l'inquisition, lequel était à
côté de lui, prit poliment la parole et dit: Apparemment que
monsieur ne croit pas au péché originel; car si tout est au
mieux, il n'y a donc eu ni chute ni punition.
Je demande très humblement pardon à votre excellence, répondit
Pangloss encore plus poliment, car la chute de l'homme et la
malédiction entraient nécessairement dans le meilleur des mondes
possibles. Monsieur ne croit donc pas à la liberté? dit le
familier. Votre excellence m'excusera, dit Pangloss; la liberté
peut subsister avec la nécessité absolue; car il était nécessaire
que nous fussions libres; car enfin la volonté déterminée......
Pangloss était au milieu de sa phrase, quand Je familier fit un
signe de tête à son estafier qui lui servait à boire du vin de
Porto ou d'Oporto.

View File

@ -0,0 +1,510 @@
This file was derived from
http://www.gutenberg.org/cache/epub/4650/pg4650.txt
--------
CANDIDE,
ou
L'OPTIMISME,
TRADUIT DE L'ALLEMAND
DE M. LE DOCTEUR RALPH,
AVEC LES ADDITIONS
QU'ON A TROUVÉES DANS LA POCHE DU DOCTEUR, LORSQU'IL MOURUT
À MINDEN, L'AN DE GRÂCE 1759
1759
CHAPITRE I.
Comment Candide fut élevé dans un beau château, et comment il fut
chassé d'icelui.
Il y avait en Vestphalie, dans le château de M. le baron de
Thunder-ten-tronckh, un jeune garçon à qui la nature avait donné
les moeurs les plus douces. Sa physionomie annonçait son âme.
Il avait le jugement assez droit, avec l'esprit le plus simple;
c'est, je crois, pour cette raison qu'on le nommait Candide. Les
anciens domestiques de la maison soupçonnaient qu'il était fils
de la soeur de monsieur le baron et d'un bon et honnête
gentilhomme du voisinage, que cette demoiselle ne voulut jamais
épouser parce qu'il n'avait pu prouver que soixante et onze
quartiers, et que le reste de son arbre généalogique avait été
perdu par l'injure du temps.
Monsieur le baron était un des plus puissants seigneurs de la
Westphalie, car son château avait une porte et des fenêtres. Sa
grande salle même était ornée d'une tapisserie. Tous les chiens
de ses basses-cours composaient une meute dans le besoin; ses
palefreniers étaient ses piqueurs; le vicaire du village était
son grand-aumônier. Ils l'appelaient tous monseigneur, et ils
riaient quand il fesait des contes.
Madame la baronne, qui pesait environ trois cent cinquante
livres, s'attirait par là une très grande considération, et
fesait les honneurs de la maison avec une dignité qui la rendait
encore plus respectable. Sa fille Cunégonde, âgée de dix-sept
ans, était haute en couleur, fraîche, grasse, appétissante. Le
fils du baron paraissait en tout digne de son père. Le
précepteur Pangloss[1] était l'oracle de la maison, et le petit
Candide écoutait ses leçons avec toute la bonne foi de son âge et
de son caractère.
[1] De _pan_, tout, et _glossa_, langue. B.
Pangloss enseignait la métaphysico-théologo-cosmolonigologie. Il
prouvait admirablement qu'il n'y a point d'effet sans cause, et
que, dans ce meilleur des mondes possibles, le château de
monseigneur le baron était le plus beau des châteaux, et madame
la meilleure des baronnes possibles.
Il est démontré, disait-il, que les choses ne peuvent être
autrement; car tout étant fait pour une fin, tout est
nécessairement pour la meilleure fin. Remarquez bien que les nez
ont été faits pour porter des lunettes; aussi avons-nous des
lunettes[2]. Les jambes sont visiblement instituées pour être
chaussées, et nous avons des chausses. Les pierres ont été
formées pour être taillées et pour en faire des châteaux; aussi
monseigneur a un très beau château: le plus grand baron de la
province doit être le mieux logé; et les cochons étant faits pour
être mangés, nous mangeons du porc toute l'année: par conséquent,
ceux qui ont avancé que tout est bien ont dit une sottise; il
fallait dire que tout est au mieux.
[2] Voyez tome XXVII, page 528; et dans les _Mélanges_, année
1738, le chapitre XI de la troisième partie des _Éléments de la
philosophie de Newton_; et année 1768, le chapitre X des
_Singularités de la nature_. B.
Candide écoutait attentivement, et croyait innocemment; car il
trouvait mademoiselle Cunégonde extrêmement belle, quoiqu'il ne
prît jamais la hardiesse de le lui dire. Il concluait qu'après
le bonheur d'être né baron de Thunder-ten-tronckh, le second
degré de bonheur était d'être mademoiselle Cunégonde; le
troisième, de la voir tous les jours; et le quatrième, d'entendre
maître Pangloss, le plus grand philosophe de la province, et par
conséquent de toute la terre.
Un jour Cunégonde, en se promenant auprès du château, dans le
petit bois qu'on appelait parc, vit entre des broussailles le
docteur Pangloss qui donnait une leçon de physique expérimentale
à la femme de chambre de sa mère, petite brune très jolie et très
docile. Comme mademoiselle Cunégonde avait beaucoup de
disposition pour les sciences, elle observa, sans souffler, les
expériences réitérées dont elle fut témoin; elle vit clairement
la raison suffisante du docteur, les effets et les causes, et
s'en retourna tout agitée, toute pensive, toute remplie du désir
d'être savante, songeant qu'elle pourrait bien être la raison
suffisante du jeune Candide, qui pouvait aussi être la sienne.
Elle rencontra Candide en revenant au château, et rougit: Candide
rougit aussi . Elle lui dit bonjour d'une voix entrecoupée; et
Candide lui parla sans savoir ce qu'il disait. Le lendemain,
après le dîner, comme on sortait de table, Cunégonde et Candide
se trouvèrent derrière un paravent; Cunégonde laissa tomber son
mouchoir, Candide le ramassa; elle lui prit innocemment la main;
le jeune homme baisa innocemment la main de la jeune demoiselle
avec une vivacité, une sensibilité, une grâce toute particulière;
leurs bouches se rencontrèrent, leurs yeux s'enflammèrent, leurs
genoux tremblèrent, leurs mains s'égarèrent. M. le baron de
Thunder-ten-tronckh passa auprès du paravent, et voyant cette
cause et cet effet, chassa Candide du château à grands coups de
pied dans le derrière. Cunégonde s'évanouit: elle fut souffletée
par madame la baronne dès qu'elle fut revenue à elle-même; et
tout fut consterné dans le plus beau et le plus agréable des
châteaux possibles.
CHAPITRE II
Ce que devint Candide parmi les Bulgares.
Candide, chassé du paradis terrestre, marcha longtemps sans
savoir où, pleurant, levant les yeux au ciel, les tournant
souvent vers le plus beau des châteaux qui renfermait la plus
belle des baronnettes; il se coucha sans souper au milieu des
champs entre deux sillons; la neige tombait à gros flocons.
Candide, tout transi, se traîna le lendemain vers la ville
voisine, qui s'appelle _Valdberghoff-trarbk-dikdorff_, n'ayant
point d'argent, mourant de faim et de lassitude. Il s'arrêta
tristement à la porte d'un cabaret. Deux hommes habillés de bleu
le remarquèrent: Camarade, dit l'un, voilà un jeune homme très
bien fait, et qui a la taille requise; ils s'avancèrent vers
Candide et le prièrent à dîner très civilement.--Messieurs, leur
dit Candide avec une modestie charmante, vous me faites beaucoup
d'honneur, mais je n'ai pas de quoi payer mon écot.--Ah!
monsieur, lui dit un des bleus, les personnes de votre figure et
de votre mérite ne paient jamais rien: n'avez-vous pas cinq pieds
cinq pouces de haut?--Oui, messieurs, c'est ma taille, dit-il en
fesant la révérence.--Ah! monsieur, mettez-vous à table; non
seulement nous vous défraierons, mais nous ne souffrirons jamais
qu'un homme comme vous manque d'argent; les hommes ne sont faits
que pour se secourir les uns les autres.--Vous avez raison, dit
Candide; c'est ce que M. Pangloss m'a toujours dit, et je vois
bien que tout est au mieux. On le prie d'accepter quelques écus,
il les prend et veut faire son billet; on n'en veut point, on se
met à table. N'aimez-vous pas tendrement?....--Oh! oui,
répond-il, j'aime tendrement mademoiselle Cunégonde.--Non, dit
l'un de ces messieurs, nous vous demandons si vous n'aimez pas
tendrement le roi des Bulgares?--Point du tout, dit-il, car je ne
l'ai jamais vu.--Comment! c'est le plus charmant des rois, et il
faut boire à sa santé.--Oh! très volontiers, messieurs. Et il
boit. C'en est assez, lui dit-on, vous voilà l'appui, le
soutien, le défenseur, le héros des Bulgares; votre fortune est
faite, et votre gloire est assurée. On lui met sur-le-champ les
fers aux pieds, et on le mène au régiment. On le fait tourner à
droite, à gauche, hausser la baguette, remettre la baguette,
coucher en joue, tirer, doubler le pas, et on lui donne trente
coups de bâton; le lendemain, il fait l'exercice un peu moins
mal, et il ne reçoit que vingt coups; le surlendemain, on ne lui
en donne que dix, et il est regardé par ses camarades comme un
prodige.
Candide, tout stupéfait, ne démêlait pas encore trop bien comment
il était un héros. Il s'avisa un beau jour de printemps de
s'aller promener, marchant tout droit devant lui, croyant que
c'était un privilège de l'espèce humaine, comme de l'espèce
animale, de se servir de ses jambes à son plaisir. Il n'eut pas
fait deux lieues que voilà quatre autres héros de six pieds qui
l'atteignent, qui le lient, qui le mènent dans un cachot. On lui
demanda juridiquement ce qu'il aimait le mieux d'être fustigé
trente-six fois par tout le régiment, ou de recevoir à-la-fois
douze balles de plomb dans la cervelle. Il eut beau dire que les
volontés sont libres, et qu'il ne voulait ni l'un ni l'autre, il
fallut faire un choix; il se détermina, en vertu du don de Dieu
qu'on nomme _liberté_, à passer trente-six fois par les
baguettes; il essuya deux promenades. Le régiment était composé
de deux mille hommes; cela lui composa quatre mille coups de
baguette, qui, depuis la nuque du cou jusqu'au cul, lui
découvrirent les muscles et les nerfs. Comme on allait procéder
à la troisième course, Candide, n'en pouvant plus, demanda en
grâce qu'on voulût bien avoir la bonté de lui casser la tête; il
obtint cette faveur; on lui bande les yeux; on le fait mettre à
genoux. Le roi des Bulgares passe dans ce moment, s'informe du
crime du patient; et comme ce roi avait un grand génie, il
comprit, par tout ce qu'il apprit de Candide, que c'était un
jeune métaphysicien fort ignorant des choses de ce monde, et il
lui accorda sa grâce avec une clémence qui sera louée dans tous
les journaux et dans tous les siècles. Un brave chirurgien
guérit Candide en trois semaines avec les émollients enseignés
par Dioscoride. Il avait déjà un peu de peau et pouvait marcher,
quand le roi des Bulgares livra bataille au roi des Abares.
CHAPITRE III.
Comment Candide se sauva d'entre les Bulgares, et ce qu'il
devint.
Rien n'était si beau, si leste, si brillant, si bien ordonné que
les deux armées. Les trompettes, les fifres, les hautbois, les
tambours, les canons; formaient une harmonie telle qu'il n'y en
eut jamais en enfer. Les canons renversèrent d'abord à peu près
six mille hommes de chaque côté; ensuite la mousqueterie ôta du
meilleur des mondes environ neuf à dix mille coquins qui en
infectaient la surface. La baïonnette fut aussi la raison
suffisante de la mort de quelques milliers d'hommes. Le tout
pouvait bien se monter à une trentaine de mille âmes. Candide,
qui tremblait comme un philosophe, se cacha du mieux qu'il put
pendant cette boucherie héroïque.
Enfin, tandis que les deux rois fesaient chanter des _Te Deum_,
chacun dans son camp, il prit le parti d'aller raisonner ailleurs
des effets et des causes. Il passa par-dessus des tas de morts
et de mourants, et gagna d'abord un village voisin; il était en
cendres: c'était un village abare que les Bulgares avaient brûlé,
selon les lois du droit public. Ici des vieillards criblés de
coups regardaient mourir leurs femmes égorgées, qui tenaient
leurs enfants à leurs mamelles sanglantes; là des filles
éventrées après avoir assouvi les besoins naturels de quelques
héros, rendaient les derniers soupirs; d'autres à demi brûlées
criaient qu'on achevât de leur donner la mort. Des cervelles
étaient répandues sur la terre à côté de bras et de jambes
coupés.
Candide s'enfuit au plus vite dans un autre village: il
appartenait à des Bulgares, et les héros abares l'avaient traité
de même. Candide, toujours marchant sur des membres palpitants
ou à travers des ruines, arriva enfin hors du théâtre de la
guerre, portant quelques petites provisions dans son bissac, et
n'oubliant jamais mademoiselle Cunégonde. Ses provisions lui
manquèrent quand il fut en Hollande; mais ayant entendu dire que
tout le monde était riche dans ce pays-là, et qu'on y était
chrétien, il ne douta pas qu'on ne le traitât aussi bien qu'il
l'avait été dans le château de M. le baron, avant qu'il en eût
été chassé pour les beaux yeux de mademoiselle Cunégonde.
Il demanda l'aumône à plusieurs graves personnages, qui lui
répondirent tous que, s'il continuait à faire ce métier, on
l'enfermerait dans une maison de correction pour lui apprendre à
vivre.
Il s'adressa ensuite à un homme qui venait de parler tout seul
une heure de suite sur la charité dans une grande assemblée. Cet
orateur le regardant de travers lui dit: Que venez-vous faire
ici? y êtes-vous pour la bonne cause? Il n'y a point d'effet sans
cause, répondit modestement Candide; tout est enchaîné
nécessairement et arrangé pour le mieux. Il a fallu que je fusse
chassé d'auprès de mademoiselle Cunégonde, que j'aie passé par
les baguettes, et il faut que je demande mon pain, jusqu'à ce que
je puisse en gagner; tout cela ne pouvait être autrement. Mon
ami, lui dit l'orateur, croyez-vous que le pape soit
l'antechrist? Je ne l'avais pas encore entendu dire, répondit
Candide: mais qu'il le soit, ou qu'il ne le soit pas, je manque
de pain. Tu ne mérites pas d'en manger, dit l'autre: va, coquin,
va, misérable, ne m'approche de ta vie. La femme de l'orateur
ayant mis la tête à la fenêtre, et avisant un homme qui doutait
que le pape fût antechrist, lui répandit sur le chef un
plein..... O ciel! à quel excès se porte le zèle de la religion
dans les dames!
Un homme qui n'avait point été baptisé, un bon anabaptiste, nommé
Jacques, vit la manière cruelle et ignominieuse dont on traitait
ainsi un de ses frères, un être à deux pieds sans plumes, qui
avait une âme; il l'amena chez lui, le nettoya, lui donna du pain
et de la bière, lui fit présent de deux florins, et voulut même
lui apprendre à travailler dans ses manufactures aux étoffes de
Perse qu'on fabrique en Hollande. Candide se prosternant presque
devant lui, s'écriait: Maître Pangloss me l'avait bien dit que
tout est au mieux dans ce monde, car je suis infiniment plus
touché de votre extrême générosité que de la dureté de ce
monsieur à manteau noir, et de madame son épouse.
Le lendemain, en se promenant, il rencontra un gueux tout couvert
de pustules, les yeux morts, le bout du nez rongé, la bouche de
travers, les dents noires, et parlant de la gorge, tourmenté
d'une toux violente, et crachant une dent à chaque effort.
CHAPITRE IV.
Comment Candide rencontra son ancien maître de philosophie, le
docteur Pangloss, et ce qui en advint.
Candide, plus ému encore de compassion que d'horreur, donna à cet
épouvantable gueux les deux florins qu'il avait reçus de son
honnête anabaptiste Jacques. Le fantôme le regarda fixement,
versa des larmes, et sauta à son cou. Candide effrayé recule.
Hélas! dit le misérable à l'autre misérable, ne reconnaissez-vous
plus votre cher Pangloss? Qu'entends-je? vous, mon cher maître!
vous, dans cet état horrible! quel malheur vous est-il donc
arrivé? pourquoi n'êtes-vous plus dans le plus beau des châteaux?
qu'est devenue mademoiselle Cunégonde, la perle des filles, le
chef-d'oeuvre de la nature? Je n'en peux plus, dit Pangloss.
Aussitôt Candide le mena dans l'étable de l'anabaptiste, où il
lui fit manger un peu de pain; et quand Pangloss fut refait: Eh
bien! lui dit-il, Cunégonde? Elle est morte, reprit l'autre.
Candide s'évanouit à ce mot: son ami rappela ses sens avec un peu
de mauvais vinaigre qui se trouva par hasard dans l'étable.
Candide rouvre les yeux. Cunégonde est morte! Ah! meilleur des
mondes, où êtes-vous? Mais de quelle maladie est-elle morte? ne
serait-ce point de m'avoir vu chasser du beau château de monsieur
son père à grands coups de pied? Non, dit Pangloss, elle a été
éventrée par des soldats bulgares, après avoir été violée autant
qu'on peut l'être; ils ont cassé la tête à monsieur le baron qui
voulait la défendre; madame la baronne a été coupée en morceaux;
mon pauvre pupille traité précisément comme sa soeur; et quant au
château, il n'est pas resté pierre sur pierre, pas une grange,
pas un mouton, pas un canard, pas un arbre; mais nous avons été
bien vengés, car les Abares en ont fait autant dans une baronnie
voisine qui appartenait à un seigneur bulgare.
A ce discours, Candide s'évanouit encore; mais revenu à soi, et
ayant dit tout ce qu'il devait dire, il s'enquit de la cause et
de l'effet, et de la raison suffisante qui avait mis Pangloss
dans un si piteux état. Hélas! dit l'autre, c'est l'amour:
l'amour, le consolateur du genre humain, le conservateur de
l'univers, l'âme de tous les êtres sensibles, le tendre amour.
Hélas! dit Candide, je l'ai connu cet amour, ce souverain des
coeurs, cette âme de notre âme; il ne m'a jamais valu qu'un
baiser et vingt coups de pied au cul. Comment cette belle cause
a-t-elle pu produire en vous un effet si abominable?
Pangloss répondit en ces termes: O mon cher Candide! vous avez
connu Paquette, cette jolie suivante de notre auguste baronne:
j'ai goûté dans ses bras les délices du paradis, qui ont produit
ces tourments d'enfer dont vous me voyez dévoré; elle en était
infectée, elle en est peut-être morte. Paquette tenait ce
présent d'un cordelier très savant qui avait remonté à la source,
car il l'avait eu d'une vieille comtesse, qui l'avait reçu d'un
capitaine de cavalerie, qui le devait à une marquise, qui le
tenait d'un page, qui l'avait reçu d'un jésuite, qui, étant
novice, l'avait eu en droite ligne d'un des compagnons de
Christophe Colomb. Pour moi, je ne le donnerai à personne, car
je me meurs.
O Pangloss! s'écria Candide, voilà une étrange généalogie!
n'est-ce pas le diable qui en fut la souche? Point du tout,
répliqua ce grand homme; c'était une chose indispensable dans le
meilleur des mondes, un ingrédient nécessaire; car si Colomb
n'avait pas attrapé dans une île de l'Amérique cette maladie[1]
qui empoisonne la source de la génération, qui souvent même
empêche la génération, et qui est évidemment l'opposé du grand
but de la nature, nous n'aurions ni le chocolat ni la cochenille;
il faut encore observer que jusqu'aujourd'hui, dans notre
continent, cette maladie nous est particulière, comme la
controverse. Les Turcs, les Indiens, les Persans, les Chinois,
les Siamois, les Japonais, ne la connaissent pas encore; mais il
y a une raison suffisante pour qu'ils la connaissent à leur tour
dans quelques siècles. En attendant elle a fait un merveilleux
progrès parmi nous, et surtout dans ces grandes armées composées
d'honnêtes stipendiaires bien élevés, qui décident du destin des
états; on peut assurer que, quand trente mille hommes combattent
en bataille rangée contre des troupes égales en nombre, il y a
environ vingt mille vérolés de chaque côté.
[1] Voyez tome XXXI, page 7. B.
Voilà qui est admirable, dit Candide; mais il faut vous faire
guérir. Et comment le puis-je? dit Pangloss; je n'ai pas le sou,
mon ami, et dans toute l'étendue de ce globe on ne peut ni se
faire saigner, ni prendre un lavement sans payer, ou sans qu'il y
ait quelqu'un qui paie pour nous.
Ce dernier discours détermina Candide; il alla se jeter aux pieds
de son charitable anabaptiste Jacques, et lui fit une peinture si
touchante de l'état où son ami était réduit, que le bon-homme
n'hésita pas à recueillir le docteur Pangloss; il le fit guérir à
ses dépens. Pangloss, dans la cure, ne perdit qu'un oeil et une
oreille. Il écrivait bien, et savait parfaitement
l'arithmétique. L'anabaptiste Jacques en fit son teneur de
livres. Au bout de deux mois, étant obligé d'aller à Lisbonne
pour les affaires de son commerce, il mena dans son vaisseau ses
deux philosophes. Pangloss lui expliqua comment tout était on ne
peut mieux. Jacques n'était pas de cet avis. Il faut bien,
disait-il, que les hommes aient un peu corrompu la nature, car
ils ne sont point nés loups, et ils sont devenus loups. Dieu ne
leur a donné ni canons de vingt-quatre, ni baïonnettes, et ils se
sont fait des baïonnettes et des canons pour se détruire. Je
pourrais mettre en ligne de compte les banqueroutes, et la
justice qui s'empare des biens des banqueroutiers pour en
frustrer les créanciers. Tout cela était indispensable,
répliquait le docteur borgne, et les malheurs particuliers font
le bien général; de sorte que plus il y a de malheurs
particuliers, et plus tout est bien. Tandis qu'il raisonnait,
l'air s'obscurcit, les vents soufflèrent des quatre coins du
monde, et le vaisseau fut assailli de la plus horrible tempête, à
la vue du port de Lisbonne.
CHAPITRE V.
Tempête, naufrage, tremblement de terre, et ce qui advint du
docteur Pangloss, de Candide, et de l'anabaptiste Jacques.
La moitié des passagers affaiblis, expirants de ces angoisses
inconcevables que le roulis d'un vaisseau porte dans les nerfs et
dans toutes les humeurs du corps agitées en sens contraires,
n'avait pas même la force de s'inquiéter du danger. L'autre
moitié jetait des cris et fesait des prières; les voiles étaient
déchirées, les mâts brisés, le vaisseau entr'ouvert. Travaillait
qui pouvait, personne ne s'entendait, personne ne commandait.
L'anabaptiste aidait un peu à la manoeuvre; il était sur le
tillac; un matelot furieux le frappe rudement et l'étend sur les
planches; mais du coup qu'il lui donna, il eut lui-même une si
violente secousse, qu'il tomba hors du vaisseau, la tête la
première. Il restait suspendu et accroché à une partie de mât
rompu. Le bon Jacques court à son secours, l'aide à remonter, et
de l'effort qu'il fait, il est précipité dans la mer à la vue du
matelot, qui le laissa périr sans daigner seulement le regarder.
Candide approche, voit son bienfaiteur qui reparaît un moment, et
qui est englouti pour jamais. Il veut se jeter après lui dans la
mer: le philosophe Pangloss l'en empêche, en lui prouvant que la
rade de Lisbonne avait été formée exprès pour que cet anabaptiste
s'y noyât. Tandis qu'il le prouvait _à priori_, le vaisseau
s'entr'ouvre, tout périt à la réserve de Pangloss, de Candide, et
de ce brutal de matelot qui avait noyé le vertueux anabaptiste;
le coquin nagea heureusement jusqu'au rivage, où Pangloss et
Candide furent portés sur une planche.
Quand ils furent revenus un peu à eux, ils marchèrent vers
Lisbonne; il leur restait quelque argent, avec lequel ils
espéraient se sauver de la faim après avoir échappé à la tempête.
A peine ont-ils mis le pied dans la ville, en pleurant la mort de
leur bienfaiteur, qu'ils sentent la terre trembler sous leurs
pas[1]; la mer s'élève en bouillonnant dans le port, et brise les
vaisseaux qui sont à l'ancre. Des tourbillons de flammes et de
cendres couvrent les rues et les places publiques; les maisons
s'écroulent, les toits sont renversés sur les fondements, et les
fondements se dispersent; trente mille habitants de tout âge et
de tout sexe sont écrasés sous des ruines. Le matelot disait en
sifflant et en jurant: il y aura quelque chose à gagner ici.
Quelle peut être la raison suffisante de ce phénomène? disait
Pangloss. Voici le dernier jour du monde! s'écriait Candide.
Le matelot court incontinent au milieu des débris, affronte la
mort pour trouver de l'argent, en trouve, s'en empare, s'enivre,
et ayant cuvé son vin, achète les faveurs de la première fille de
bonne volonté qu'il rencontre sur les ruines des maisons
détruites, et au milieu des mourants et des morts. Pangloss le
tirait cependant par la manche: Mon ami, lui disait-il, cela
n'est pas bien, vous manquez à la raison universelle, vous prenez
mal votre temps. Tête et sang, répondit l'autre, je suis matelot
et né à Batavia; j'ai marché quatre fois sur le crucifix dans
quatre voyages au Japon[2]; tu as bien trouvé ton homme avec ta
raison universelle!
[1] Le tremblement de terre de Lisbonne est du 1er novembre 1755.
B.
[2] Voyez tome XVIII, page 470. B.
Quelques éclats de pierre avaient blessé Candide; il était étendu
dans la rue et couvert de débris. Il disait à Pangloss: Hélas!
procure-moi un peu de vin et d'huile; je me meurs. Ce
tremblement de terre n'est pas une chose nouvelle, répondit
Pangloss; la ville de Lima éprouva les mêmes secousses en
Amérique l'année passée; mêmes causes, mêmes effets; il y a
certainement une traînée de soufre sous terre depuis Lima jusqu'à
Lisbonne. Rien n'est plus probable, dit Candide; mais, pour
Dieu, un peu d'huile et de vin. Comment probable? répliqua le
philosophe, je soutiens que la chose est démontrée. Candide
perdit connaissance, et Pangloss lui apporta un peu d'eau d'une
fontaine voisine.
Le lendemain, ayant trouvé quelques provisions de bouche en se
glissant à travers des décombres, ils réparèrent un peu leurs
forces. Ensuite ils travaillèrent comme les autres à soulager
les habitants échappés à la mort. Quelques citoyens, secourus
par eux, leur donnèrent un aussi bon dîner qu'on le pouvait dans
un tel désastre: il est vrai que le repas était triste; les
convives arrosaient leur pain de leurs larmes; mais Pangloss les
consola, en les assurant que les choses ne pouvaient être
autrement: Car, dit-il, tout ceci est ce qu'il y a de mieux; car
s'il y a un volcan à Lisbonne, il ne pouvait être ailleurs; car
il est impossible que les choses ne soient pas où elles sont, car
tout est bien.
Un petit homme noir, familier de l'inquisition, lequel était à
côté de lui, prit poliment la parole et dit: Apparemment que
monsieur ne croit pas au péché originel; car si tout est au
mieux, il n'y a donc eu ni chute ni punition.
Je demande très humblement pardon à votre excellence, répondit
Pangloss encore plus poliment, car la chute de l'homme et la
malédiction entraient nécessairement dans le meilleur des mondes
possibles. Monsieur ne croit donc pas à la liberté? dit le
familier. Votre excellence m'excusera, dit Pangloss; la liberté
peut subsister avec la nécessité absolue; car il était nécessaire
que nous fussions libres; car enfin la volonté déterminée......
Pangloss était au milieu de sa phrase, quand Je familier fit un
signe de tête à son estafier qui lui servait à boire du vin de
Porto ou d'Oporto.

View File

@ -0,0 +1,178 @@
This file was derived from
http://www.gutenberg.org/cache/epub/1982/pg1982.txt
--------
羅生門
芥川龍之介
 或日の暮方の事である。一人の下人が、羅生門の下で雨やみを待っていた。 広い門
の下には、この男の外に誰もいない。ただ、所々丹塗の剥げた、大きな円柱に、きりぎ
りすが一匹とまっている。羅生門が、朱雀大路にある以上は、この男の外にも、雨やみ
をする市女笠や揉烏帽子が、もう二三人はありそうなものである。それが、この男の外
に誰もいない。
 何故かと云うと、この二三年、京都には、地震とか辻風とか火事とか饑饉とか云う災
いがつづいて起こった。そこで洛中のさびれ方は一通りでない。旧記によると、仏像や
仏具を打砕いて、その丹がついたり、金銀の箔(はく)がついたりした木を、路ばたに
つみ重ねて薪の料(しろ)に売っていたと云うことである。洛中がその始末であるから、
羅生門の修理などは、元より誰も捨てて顧みる者がなかった。するとその荒れ果てたの
をよい事にして、狐狸(こり)が棲む。盗人が棲む。とうとうしまいには、引取り手の
ない死人を、この門へ持って来て、捨てて行くと云う習慣さえ出来た。そこで、日の目
が見えなくなると、誰でも気味を悪がって、この門の近所へは足ぶみをしない事になっ
てしまったのである。
 その代り又鴉が何処からか、たくさん集まって来た。昼間見ると、その鴉が何羽とな
く輪を描いて、高い鴟尾(しび)のまわりを啼きながら、飛びまわっている。殊に門の
上の空が、夕焼けであかくなる時には、それが胡麻をまいたようにはっきり見えた。鴉
は、勿論、門の上にある死人の肉を、啄みに来るのである。ーー尤も今日は、刻限が遅
いせいか、一羽も見えない。唯、所々、崩れかかった、そうしてその崩れ目に長い草の
はえた石段の上に、鴉の糞(くそ)が、点々と白くこびりついているのが見える。下人
は七段ある石段の一番上の段に洗いざらした紺の襖(あお)の尻を据えて、右の頬に出
来た、大きな面皰(にきび)を気にしながら、ぼんやり、雨のふるのを眺めているので
ある。
 作者はさっき、「下人が雨やみを待っていた」と書いた。しかし、下人は、雨がやん
でも格別どうしようと云う当てはない。ふだんなら、勿論、主人の家へ帰る可き筈であ
る。所がその主人からは、四五日前に暇を出された。前にも書いたように、当時京都の
町は一通りならず衰微していた。今この下人が、永年、使われていた主人から暇を出さ
れたのも、この衰微の小さな余波に外ならない。だから、「下人が雨やみを待っていた」
と云うよりも、「雨にふりこめられた下人が、行き所がなくて、途方にくれていた」と
云う方が、適当である。その上、今日の空模様も少なからずこの平安朝の下人の
Sentimentalismeに影響した。申さるの刻下がりからふり出した雨は、未だに上
がるけしきがない。そこで、下人は、何を措いても差当たり明日の暮しをどうにかしよ
うとしてーー云わばどうにもならない事を、どうにかしようとして、とりとめもない考
えをたどりながら、さっきから朱雀大路にふる雨の音を聞くともなく聞いていた。
 雨は羅生門をつつんで、遠くから、ざあっと云う音をあつめてくる。夕闇は次第に空
を低くして、見上げると、門の屋根が、斜めにつき出した甍(いらか)の先に、重たく
うす暗い雲を支えている。
 どうにもならない事を、どうにかする為には、手段を選んでいる遑(いとま)はない。
選んでいれば、築地(ついじ)の下か、道ばたの土の上で、饑死(うえじに)をするば
かりである。そうして、この門の上へ持って来て、犬のように捨てられてしまうばかり
である。選ばないとすればーー下人の考えは、何度も同じ道を低徊した揚句に、やっと
この局所へ逢着した。しかしこの「すれば」は、いつもでたっても、結局「すれば」で
あった。下人は、手段を選ばないという事を肯定しながらも、この「すれば」のかたを
つける為に、当然、この後に来る可き「盗人になるより外に仕方がない」と云う事を、
積極的に肯定するだけの、勇気が出ずにいたのである。
 下人は大きな嚏(くさめ)をして、それから、大儀そうに立上がった。夕冷えのする
京都は、もう火桶が欲しい程の寒さである。風は門の柱と柱との間を、夕闇と共に遠慮
なく、吹きぬける。丹塗の柱にとまっていたきりぎりすも、もうどこかへ行ってしまっ
た。
 下人は、頸をちぢめながら、山吹の汗衫(かざみ)に重ねた、紺の襖の肩を高くして
門のまわりを見まわした。雨風の患のない、人目にかかる惧のない、一晩楽にねられそ
うな所があれば、そこでともかくも、夜を明かそうと思ったからである。すると、幸門
の上の楼へ上る、幅の広い、之も丹を塗った梯子が眼についた。上なら、人がいたにし
ても、どうせ死人ばかりである。下人は、そこで腰にさげた聖柄(ひじりづか)の太刀
が鞘走らないように気をつけながら、藁草履をはいた足を、その梯子の一番下の段へふ
みかけた。
 それから、何分かの後である。羅生門の楼の上へ出る、幅の広い梯子の中段に、一人
の男が、猫のように身をちぢめて、息を殺しながら、上の容子を窺っていた。楼の上か
らさす火の光が、かすかに、その男の右の頬をぬらしている。短い鬚(ひげ)の中に、
赤く膿を持った面皰のある頬である。下人は、始めから、この上にいる者は、死人ばか
りだと高を括っていた。それが、梯子を二三段上って見ると、上では誰か火をとぼして、
しかもその火を其処此処と動かしているらしい。これは、その濁った、黄いろい光が、
隅々に蜘蛛の巣をかけた天井裏に、ゆれながら映ったので、すぐにそれと知れたのであ
る。この雨の夜に、この羅生門の上で、火をともしているからは、どうせ唯の者ではな
い。
 下人は、宮守(やもり)のように足音をぬすんで、やっと急な梯子を、一番上の段ま
で這うようにして上りつめた。そうして体を出来るだけ、平にしながら、頸を出来るだ
け、前へ出して、恐る恐る、楼の内を覗いて見た。
 見ると、楼の内には、噂に聞いた通り、幾つかの屍骸(しがい)が、無造作に棄てて
あるが、火の光の及ぶ範囲が、思ったより狭いので、数は幾つともわからない。唯、お
ぼろげながら、知れるのは、その中に裸の屍骸と、着物を着た屍骸とがあると云う事で
ある。勿論、中には女も男もまじっているらしい。そうして、その屍骸は皆、それが、
嘗(かつて)、生きていた人間だと云う事実さえ疑われる程、土を捏ねて造った人形の
ように、口を開いたり、手を延ばしたりして、ごろごろ床の上にころがっていた。しか
も、肩とか胸とかの高くなっている部分に、ぼんやりした火の光をうけて、低くなって
いる部分の影を一層暗くしながら、永久に唖(おし)の如く黙っていた。
 下人は、それらの屍骸の腐爛した臭気に思わず、鼻を掩った(おおった)。しかし、
その手は、次の瞬間には、もう鼻を掩う事を忘れていた。或る強い感情が殆悉(ほとん
どことごとく)この男の嗅覚を奪ってしまったからである。
 下人の眼は、その時、はじめて、其屍骸の中に蹲っている(うずくまっている)人間
を見た。檜肌色(ひはだいろ)の着物を著た、背の低い、痩せた、白髪頭の、猿のよう
な老婆である。その老婆は、右の手に火をともした松の木片を持って、その屍骸の一つ
の顔を覗きこむように眺めていた。髪の毛の長い所を見ると、多分女の屍骸であろう。
 下人は、六分の恐怖と四分の好奇心とに動かされて、暫時は呼吸(いき)をするのさ
え忘れていた。旧記の記者の語を借りれば、「頭身(とうしん)の毛も太る」ように感
じたのである。すると、老婆は、松の木片を、床板の間に挿して、それから、今まで眺
めていた屍骸の首に両手をかけると、丁度、猿の親が猿の子の虱(しらみ)をとるよう
に、その長い髪の毛を一本ずつ抜きはじめた。髪は手に従って抜けるらしい。
 その髪の毛が、一本ずつ抜けるのに従って下人の心からは、恐怖が少しずつ消えて行っ
た。そうして、それと同時に、その老婆に対するはげしい憎悪が、少しずつ動いて来た。
いや、この老婆に対すると云っては、語弊があるかも知れない。寧(むしろ)、あらゆ
る悪に対する反感が、一分毎に強さを増して来たのである。この時、誰かがこの下人に、
さっき門の下でこの男が考えていた、饑死(うえじに)をするか盗人になるかと云う問
題を、改めて持出したら、恐らく下人は、何の未練もなく、饑死を選んだ事であろう。
それほど、この男の悪を憎む心は、老婆の床に挿した松の木片のように、勢よく燃え上
がりだしていたのである。
 下人には、勿論、何故老婆が死人の髪の毛を抜くかわからなかった。従って、合理的
には、それを善悪の何れに片づけてよいか知らなかった。しかし下人にとっては、この
雨の夜に、この羅生門の上で、死人の髪の毛を抜くと云う事が、それだけで既に許す可
らざる悪であった。勿論 下人は さっき迄自分が、盗人になる気でいた事なぞは と
うに忘れているのである。
 そこで、下人は、両足に力を入れて、いかなり、梯子から上へ飛び上がった そうし
て聖柄(ひじりづか)の太刀に手をかけながら、大股に老婆の前へ歩みよった。老婆が
驚いたのは 云う迄もない。
 老婆は、一目下人を見ると、まるで弩(いしゆみ)にでも弾かれたように 飛び上がっ
た。
 「おのれ、どこへ行く。」
 下人は、老婆が屍骸につまづきながら、慌てふためいて逃げようとする行手を塞いで、
こう罵った。老婆は、それでも下人をつきのけて行こうとする。下人は又、それを行か
すまいとして、押しもどす。二人は屍骸の中で、暫、無言のまま、つかみ合った。しか
し勝負は、はじめから、わかっている。下人はとうとう、老婆の腕をつかんで、無理に
そこへねじ倒した。丁度、鶏(とり)の脚のような、骨と皮ばかりの腕である。
 「何をしていた。さあ何をしていた。云え。云わぬと これだぞよ。」
 下人は、老婆をつき放すと、いきなり、太刀の鞘を払って、白い鋼(はがね)の色を
その眼の前へつきつけた。けれども、老婆は黙っている。両手をわなわなふるわせて、
肩で息を切りながら、眼を、眼球がまぶたの外へ出そうになる程、見開いて、唖のよう
に執拗(しゅうね)く黙っている。これを見ると、下人は始めて明白にこの老婆の生死
が、全然、自分の意志に支配されていると云う事を意識した。そうして、この意識は、
今まではげしく燃えていた憎悪の心を何時(いつ)の間にか冷ましてしまった。後に残っ
たのは、唯、或仕事をして、それが円満に成就した時の、安らかな得意と満足とがある
ばかりである。そこで、下人は、老婆を、見下げながら、少し声を柔げてこう云った。
 「己は検非違使(けびいし)の庁の役人などではない。今し方この門の下を通りかかっ
た旅の者だ。だからお前に縄をかけて、どうしようと云うような事はない。唯今時分、
この門の上で、何をしていたのだか、それを己に話さえすればいいのだ。」
 すると、老婆は、見開いた眼を、一層大きくして、じっとその下人の顔を見守った。
まぶたの赤くなった、肉食鳥のような、鋭い眼で見たのである。それから、皺で、殆、
鼻と一つになった唇を何か物でも噛んでいるように動かした。細い喉で、尖った喉仏の
動いているのが見える。その時、その喉から、鴉(からす)の啼くような声が、喘ぎ喘
ぎ、下人の耳へ伝わって来た。
 「この髪を抜いてな、この女の髪を抜いてな、鬘(かつら)にしようと思うたの
じゃ。」
 下人は、老婆の答が存外、平凡なのに失望した。そうして失望すると同時に、又前の
憎悪が、冷な侮蔑と一しょに、心の中へはいって来た。すると その気色(けしき)が、
先方へも通じたのであろう。老婆は、片手に、まだ屍骸の頭から奪(と)った長い抜け
毛を持ったなり、蟇(ひき)のつぶやくような声で、口ごもりながら、こんな事を云っ
た。
 成程、死人の髪の毛を抜くと云う事は、悪い事かね知れぬ。しかし、こう云う死人の
多くは、皆 その位な事を、されてもいい人間ばかりである。現に、自分が今、髪を抜
いた女などは、蛇を四寸ばかりずつに切って干したのを、干魚(ほしうお)だと云って、
太刀帯(たちはき)の陣へ売りに行った。疫病にかかって死ななかったなら、今でも売
りに行っていたかもしれない。しかも、この女の売る干魚は、味がよいと云うので、太
刀帯たちが、欠かさず菜料に買っていたのである。自分は、この女のした事が悪いとは
思わない。しなければ、饑死(えうじに)をするので、仕方がなくした事だからである。
だから、又今、自分のしていた事も悪い事とは思わない。これもやはりしなければ、饑
死をするので、仕方がなくする事だからである。そうして、その仕方がない事を、よく
知っていたこの女は、自分のする事を許してくれるのにちがいないと思うからであ
る。ーー老婆は、大体こんな意味の事を云った。
 下人は、太刀を鞘におさめて、その太刀の柄を左の手でおさえながら、冷然として、
この話を聞いていた。勿論、 右の手では、赤く頬に膿を持た大きな面皰(にきび)を
気にしながら、聞いているのである。しかし、之を聞いている中に、下人の心には、或
勇気が生まれて来た。それは さっき、門の下でこの男に欠けていた勇気である。そう
して、又さっき、この門の上へ上(あが)って、その老婆を捕えた時の勇気とは、全然、
反対な方向に動こうとする勇気である。下人は、饑死をするか盗人になるかに迷わなかっ
たばかりではない。その時のこの男の心もちから云えば、饑死などと云う事は、殆、考
える事さえ出来ない程、意識の外に追い出されていた。
 「きっと、そうか。」
 老婆の話が完ると、下人は嘲(あざけ)るような声で念を押した。そうして、一足前
へ出ると、不意に、右の手を面皰から離して、老婆の襟上(えりがみ)をつかみながら、
こう云った。
 「では、己が引剥(ひはぎ)をしようと恨むまいな。己もそうしなければ、饑死をす
る体なのだ。」
 下人は、すばやく、老婆の着物を剥ぎとった。それから、足にしがみつこうとする老
婆を、手荒く屍骸の上へ蹴倒した。梯子の口までは、僅に五歩を数えるばかりである。
下人は、剥ぎとった桧肌色の着物をわきにかかえて、またたく間に急な梯子を夜の底へ
かけ下りた。
 暫、死んだように倒れていた老婆が、屍骸の中から、その裸の体を起こしたのは、そ
れから間もなくの事である。老婆は、つぶやくような、うめくような声を立てながら、
まだ燃えている火の光をたよりに、梯子の口まで、這って行った。そうして、そこから、
短い白髪を倒(さかさま)にして、門の下を覗きこんだ。外には、唯、黒洞々(こくと
うとう)たる夜があるばかりである。
 下人は、既に、雨を冒して、京都の町へ強盗を働きに急いでいた。

View File

@ -0,0 +1,178 @@
This file was derived from
http://www.gutenberg.org/cache/epub/1982/pg1982.txt
--------
$BMe@8Lg(B
$B3)@nN6G72p(B
$B!!0?F|$NJkJ}$N;v$G$"$k!#0l?M$N2<?M$,!"Me@8Lg$N2<$G1+$d$_$rBT$C$F$$$?!#!!9-$$Lg(B
$B$N2<$K$O!"$3$NC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BN$r5/$3$7$?$N$O!"$=(B
$B$l$+$i4V$b$J$/$N;v$G$"$k!#O7GL$O!"$D$V$d$/$h$&$J!"$&$a$/$h$&$J@<$rN)$F$J$,$i!"(B
$B$^$@G3$($F$$$k2P$N8w$r$?$h$j$K!"Dt;R$N8}$^$G!"Gg$C$F9T$C$?!#$=$&$7$F!"$=$3$+$i!"(B
$BC;$$GrH1$rE]!J$5$+$5$^!K$K$7$F!"Lg$N2<$rGA$-$3$s$@!#30$K$O!"M#!"9uF6!9!J$3$/$H(B
$B$&$H$&!K$?$kLk$,$"$k$P$+$j$G$"$k!#(B
$B!!2<?M$O!"4{$K!"1+$rKA$7$F!"5~ET$ND.$X6/Ep$rF/$-$K5^$$$G$$$?!#(B

View File

@ -0,0 +1,178 @@
This file was derived from
http://www.gutenberg.org/cache/epub/1982/pg1982.txt
--------
羅生門
芥川龍之介
 或日の暮方の事である。一人の下人が、羅生門の下で雨やみを待っていた。 広い門
の下には、この男の外に誰もいない。ただ、所々丹塗の剥げた、大きな円柱に、きりぎ
りすが一匹とまっている。羅生門が、朱雀大路にある以上は、この男の外にも、雨やみ
をする市女笠や揉烏帽子が、もう二三人はありそうなものである。それが、この男の外
に誰もいない。
 何故かと云うと、この二三年、京都には、地震とか辻風とか火事とか饑饉とか云う災
いがつづいて起こった。そこで洛中のさびれ方は一通りでない。旧記によると、仏像や
仏具を打砕いて、その丹がついたり、金銀の箔(はく)がついたりした木を、路ばたに
つみ重ねて薪の料(しろ)に売っていたと云うことである。洛中がその始末であるから、
羅生門の修理などは、元より誰も捨てて顧みる者がなかった。するとその荒れ果てたの
をよい事にして、狐狸(こり)が棲む。盗人が棲む。とうとうしまいには、引取り手の
ない死人を、この門へ持って来て、捨てて行くと云う習慣さえ出来た。そこで、日の目
が見えなくなると、誰でも気味を悪がって、この門の近所へは足ぶみをしない事になっ
てしまったのである。
 その代り又鴉が何処からか、たくさん集まって来た。昼間見ると、その鴉が何羽とな
く輪を描いて、高い鴟尾(しび)のまわりを啼きながら、飛びまわっている。殊に門の
上の空が、夕焼けであかくなる時には、それが胡麻をまいたようにはっきり見えた。鴉
は、勿論、門の上にある死人の肉を、啄みに来るのである。ーー尤も今日は、刻限が遅
いせいか、一羽も見えない。唯、所々、崩れかかった、そうしてその崩れ目に長い草の
はえた石段の上に、鴉の糞(くそ)が、点々と白くこびりついているのが見える。下人
は七段ある石段の一番上の段に洗いざらした紺の襖(あお)の尻を据えて、右の頬に出
来た、大きな面皰(にきび)を気にしながら、ぼんやり、雨のふるのを眺めているので
ある。
 作者はさっき、「下人が雨やみを待っていた」と書いた。しかし、下人は、雨がやん
でも格別どうしようと云う当てはない。ふだんなら、勿論、主人の家へ帰る可き筈であ
る。所がその主人からは、四五日前に暇を出された。前にも書いたように、当時京都の
町は一通りならず衰微していた。今この下人が、永年、使われていた主人から暇を出さ
れたのも、この衰微の小さな余波に外ならない。だから、「下人が雨やみを待っていた」
と云うよりも、「雨にふりこめられた下人が、行き所がなくて、途方にくれていた」と
云う方が、適当である。その上、今日の空模様も少なからずこの平安朝の下人の
Sentimentalismeに影響した。申さるの刻下がりからふり出した雨は、未だに上
がるけしきがない。そこで、下人は、何を措いても差当たり明日の暮しをどうにかしよ
うとしてーー云わばどうにもならない事を、どうにかしようとして、とりとめもない考
えをたどりながら、さっきから朱雀大路にふる雨の音を聞くともなく聞いていた。
 雨は羅生門をつつんで、遠くから、ざあっと云う音をあつめてくる。夕闇は次第に空
を低くして、見上げると、門の屋根が、斜めにつき出した甍(いらか)の先に、重たく
うす暗い雲を支えている。
 どうにもならない事を、どうにかする為には、手段を選んでいる遑(いとま)はない。
選んでいれば、築地(ついじ)の下か、道ばたの土の上で、饑死(うえじに)をするば
かりである。そうして、この門の上へ持って来て、犬のように捨てられてしまうばかり
である。選ばないとすればーー下人の考えは、何度も同じ道を低徊した揚句に、やっと
この局所へ逢着した。しかしこの「すれば」は、いつもでたっても、結局「すれば」で
あった。下人は、手段を選ばないという事を肯定しながらも、この「すれば」のかたを
つける為に、当然、この後に来る可き「盗人になるより外に仕方がない」と云う事を、
積極的に肯定するだけの、勇気が出ずにいたのである。
 下人は大きな嚏(くさめ)をして、それから、大儀そうに立上がった。夕冷えのする
京都は、もう火桶が欲しい程の寒さである。風は門の柱と柱との間を、夕闇と共に遠慮
なく、吹きぬける。丹塗の柱にとまっていたきりぎりすも、もうどこかへ行ってしまっ
た。
 下人は、頸をちぢめながら、山吹の汗衫(かざみ)に重ねた、紺の襖の肩を高くして
門のまわりを見まわした。雨風の患のない、人目にかかる惧のない、一晩楽にねられそ
うな所があれば、そこでともかくも、夜を明かそうと思ったからである。すると、幸門
の上の楼へ上る、幅の広い、之も丹を塗った梯子が眼についた。上なら、人がいたにし
ても、どうせ死人ばかりである。下人は、そこで腰にさげた聖柄(ひじりづか)の太刀
が鞘走らないように気をつけながら、藁草履をはいた足を、その梯子の一番下の段へふ
みかけた。
 それから、何分かの後である。羅生門の楼の上へ出る、幅の広い梯子の中段に、一人
の男が、猫のように身をちぢめて、息を殺しながら、上の容子を窺っていた。楼の上か
らさす火の光が、かすかに、その男の右の頬をぬらしている。短い鬚(ひげ)の中に、
赤く膿を持った面皰のある頬である。下人は、始めから、この上にいる者は、死人ばか
りだと高を括っていた。それが、梯子を二三段上って見ると、上では誰か火をとぼして、
しかもその火を其処此処と動かしているらしい。これは、その濁った、黄いろい光が、
隅々に蜘蛛の巣をかけた天井裏に、ゆれながら映ったので、すぐにそれと知れたのであ
る。この雨の夜に、この羅生門の上で、火をともしているからは、どうせ唯の者ではな
い。
 下人は、宮守(やもり)のように足音をぬすんで、やっと急な梯子を、一番上の段ま
で這うようにして上りつめた。そうして体を出来るだけ、平にしながら、頸を出来るだ
け、前へ出して、恐る恐る、楼の内を覗いて見た。
 見ると、楼の内には、噂に聞いた通り、幾つかの屍骸(しがい)が、無造作に棄てて
あるが、火の光の及ぶ範囲が、思ったより狭いので、数は幾つともわからない。唯、お
ぼろげながら、知れるのは、その中に裸の屍骸と、着物を着た屍骸とがあると云う事で
ある。勿論、中には女も男もまじっているらしい。そうして、その屍骸は皆、それが、
嘗(かつて)、生きていた人間だと云う事実さえ疑われる程、土を捏ねて造った人形の
ように、口を開いたり、手を延ばしたりして、ごろごろ床の上にころがっていた。しか
も、肩とか胸とかの高くなっている部分に、ぼんやりした火の光をうけて、低くなって
いる部分の影を一層暗くしながら、永久に唖(おし)の如く黙っていた。
 下人は、それらの屍骸の腐爛した臭気に思わず、鼻を掩った(おおった)。しかし、
その手は、次の瞬間には、もう鼻を掩う事を忘れていた。或る強い感情が殆悉(ほとん
どことごとく)この男の嗅覚を奪ってしまったからである。
 下人の眼は、その時、はじめて、其屍骸の中に蹲っている(うずくまっている)人間
を見た。檜肌色(ひはだいろ)の着物を著た、背の低い、痩せた、白髪頭の、猿のよう
な老婆である。その老婆は、右の手に火をともした松の木片を持って、その屍骸の一つ
の顔を覗きこむように眺めていた。髪の毛の長い所を見ると、多分女の屍骸であろう。
 下人は、六分の恐怖と四分の好奇心とに動かされて、暫時は呼吸(いき)をするのさ
え忘れていた。旧記の記者の語を借りれば、「頭身(とうしん)の毛も太る」ように感
じたのである。すると、老婆は、松の木片を、床板の間に挿して、それから、今まで眺
めていた屍骸の首に両手をかけると、丁度、猿の親が猿の子の虱(しらみ)をとるよう
に、その長い髪の毛を一本ずつ抜きはじめた。髪は手に従って抜けるらしい。
 その髪の毛が、一本ずつ抜けるのに従って下人の心からは、恐怖が少しずつ消えて行っ
た。そうして、それと同時に、その老婆に対するはげしい憎悪が、少しずつ動いて来た。
いや、この老婆に対すると云っては、語弊があるかも知れない。寧(むしろ)、あらゆ
る悪に対する反感が、一分毎に強さを増して来たのである。この時、誰かがこの下人に、
さっき門の下でこの男が考えていた、饑死(うえじに)をするか盗人になるかと云う問
題を、改めて持出したら、恐らく下人は、何の未練もなく、饑死を選んだ事であろう。
それほど、この男の悪を憎む心は、老婆の床に挿した松の木片のように、勢よく燃え上
がりだしていたのである。
 下人には、勿論、何故老婆が死人の髪の毛を抜くかわからなかった。従って、合理的
には、それを善悪の何れに片づけてよいか知らなかった。しかし下人にとっては、この
雨の夜に、この羅生門の上で、死人の髪の毛を抜くと云う事が、それだけで既に許す可
らざる悪であった。勿論 下人は さっき迄自分が、盗人になる気でいた事なぞは と
うに忘れているのである。
 そこで、下人は、両足に力を入れて、いかなり、梯子から上へ飛び上がった そうし
て聖柄(ひじりづか)の太刀に手をかけながら、大股に老婆の前へ歩みよった。老婆が
驚いたのは 云う迄もない。
 老婆は、一目下人を見ると、まるで弩(いしゆみ)にでも弾かれたように 飛び上がっ
た。
 「おのれ、どこへ行く。」
 下人は、老婆が屍骸につまづきながら、慌てふためいて逃げようとする行手を塞いで、
こう罵った。老婆は、それでも下人をつきのけて行こうとする。下人は又、それを行か
すまいとして、押しもどす。二人は屍骸の中で、暫、無言のまま、つかみ合った。しか
し勝負は、はじめから、わかっている。下人はとうとう、老婆の腕をつかんで、無理に
そこへねじ倒した。丁度、鶏(とり)の脚のような、骨と皮ばかりの腕である。
 「何をしていた。さあ何をしていた。云え。云わぬと これだぞよ。」
 下人は、老婆をつき放すと、いきなり、太刀の鞘を払って、白い鋼(はがね)の色を
その眼の前へつきつけた。けれども、老婆は黙っている。両手をわなわなふるわせて、
肩で息を切りながら、眼を、眼球がまぶたの外へ出そうになる程、見開いて、唖のよう
に執拗(しゅうね)く黙っている。これを見ると、下人は始めて明白にこの老婆の生死
が、全然、自分の意志に支配されていると云う事を意識した。そうして、この意識は、
今まではげしく燃えていた憎悪の心を何時(いつ)の間にか冷ましてしまった。後に残っ
たのは、唯、或仕事をして、それが円満に成就した時の、安らかな得意と満足とがある
ばかりである。そこで、下人は、老婆を、見下げながら、少し声を柔げてこう云った。
 「己は検非違使(けびいし)の庁の役人などではない。今し方この門の下を通りかかっ
た旅の者だ。だからお前に縄をかけて、どうしようと云うような事はない。唯今時分、
この門の上で、何をしていたのだか、それを己に話さえすればいいのだ。」
 すると、老婆は、見開いた眼を、一層大きくして、じっとその下人の顔を見守った。
まぶたの赤くなった、肉食鳥のような、鋭い眼で見たのである。それから、皺で、殆、
鼻と一つになった唇を何か物でも噛んでいるように動かした。細い喉で、尖った喉仏の
動いているのが見える。その時、その喉から、鴉(からす)の啼くような声が、喘ぎ喘
ぎ、下人の耳へ伝わって来た。
 「この髪を抜いてな、この女の髪を抜いてな、鬘(かつら)にしようと思うたの
じゃ。」
 下人は、老婆の答が存外、平凡なのに失望した。そうして失望すると同時に、又前の
憎悪が、冷な侮蔑と一しょに、心の中へはいって来た。すると その気色(けしき)が、
先方へも通じたのであろう。老婆は、片手に、まだ屍骸の頭から奪(と)った長い抜け
毛を持ったなり、蟇(ひき)のつぶやくような声で、口ごもりながら、こんな事を云っ
た。
 成程、死人の髪の毛を抜くと云う事は、悪い事かね知れぬ。しかし、こう云う死人の
多くは、皆 その位な事を、されてもいい人間ばかりである。現に、自分が今、髪を抜
いた女などは、蛇を四寸ばかりずつに切って干したのを、干魚(ほしうお)だと云って、
太刀帯(たちはき)の陣へ売りに行った。疫病にかかって死ななかったなら、今でも売
りに行っていたかもしれない。しかも、この女の売る干魚は、味がよいと云うので、太
刀帯たちが、欠かさず菜料に買っていたのである。自分は、この女のした事が悪いとは
思わない。しなければ、饑死(えうじに)をするので、仕方がなくした事だからである。
だから、又今、自分のしていた事も悪い事とは思わない。これもやはりしなければ、饑
死をするので、仕方がなくする事だからである。そうして、その仕方がない事を、よく
知っていたこの女は、自分のする事を許してくれるのにちがいないと思うからであ
る。ーー老婆は、大体こんな意味の事を云った。
 下人は、太刀を鞘におさめて、その太刀の柄を左の手でおさえながら、冷然として、
この話を聞いていた。勿論、 右の手では、赤く頬に膿を持た大きな面皰(にきび)を
気にしながら、聞いているのである。しかし、之を聞いている中に、下人の心には、或
勇気が生まれて来た。それは さっき、門の下でこの男に欠けていた勇気である。そう
して、又さっき、この門の上へ上(あが)って、その老婆を捕えた時の勇気とは、全然、
反対な方向に動こうとする勇気である。下人は、饑死をするか盗人になるかに迷わなかっ
たばかりではない。その時のこの男の心もちから云えば、饑死などと云う事は、殆、考
える事さえ出来ない程、意識の外に追い出されていた。
 「きっと、そうか。」
 老婆の話が完ると、下人は嘲(あざけ)るような声で念を押した。そうして、一足前
へ出ると、不意に、右の手を面皰から離して、老婆の襟上(えりがみ)をつかみながら、
こう云った。
 「では、己が引剥(ひはぎ)をしようと恨むまいな。己もそうしなければ、饑死をす
る体なのだ。」
 下人は、すばやく、老婆の着物を剥ぎとった。それから、足にしがみつこうとする老
婆を、手荒く屍骸の上へ蹴倒した。梯子の口までは、僅に五歩を数えるばかりである。
下人は、剥ぎとった桧肌色の着物をわきにかかえて、またたく間に急な梯子を夜の底へ
かけ下りた。
 暫、死んだように倒れていた老婆が、屍骸の中から、その裸の体を起こしたのは、そ
れから間もなくの事である。老婆は、つぶやくような、うめくような声を立てながら、
まだ燃えている火の光をたよりに、梯子の口まで、這って行った。そうして、そこから、
短い白髪を倒(さかさま)にして、門の下を覗きこんだ。外には、唯、黒洞々(こくと
うとう)たる夜があるばかりである。
 下人は、既に、雨を冒して、京都の町へ強盗を働きに急いでいた。

View File

@ -0,0 +1,178 @@
This file was derived from
http://www.gutenberg.org/cache/epub/1982/pg1982.txt
--------
羅生門
芥川龍之介
 或日の暮方の事である。一人の下人が、羅生門の下で雨やみを待っていた。 広い門
の下には、この男の外に誰もいない。ただ、所々丹塗の剥げた、大きな円柱に、きりぎ
りすが一匹とまっている。羅生門が、朱雀大路にある以上は、この男の外にも、雨やみ
をする市女笠や揉烏帽子が、もう二三人はありそうなものである。それが、この男の外
に誰もいない。
 何故かと云うと、この二三年、京都には、地震とか辻風とか火事とか饑饉とか云う災
いがつづいて起こった。そこで洛中のさびれ方は一通りでない。旧記によると、仏像や
仏具を打砕いて、その丹がついたり、金銀の箔(はく)がついたりした木を、路ばたに
つみ重ねて薪の料(しろ)に売っていたと云うことである。洛中がその始末であるから、
羅生門の修理などは、元より誰も捨てて顧みる者がなかった。するとその荒れ果てたの
をよい事にして、狐狸(こり)が棲む。盗人が棲む。とうとうしまいには、引取り手の
ない死人を、この門へ持って来て、捨てて行くと云う習慣さえ出来た。そこで、日の目
が見えなくなると、誰でも気味を悪がって、この門の近所へは足ぶみをしない事になっ
てしまったのである。
 その代り又鴉が何処からか、たくさん集まって来た。昼間見ると、その鴉が何羽とな
く輪を描いて、高い鴟尾(しび)のまわりを啼きながら、飛びまわっている。殊に門の
上の空が、夕焼けであかくなる時には、それが胡麻をまいたようにはっきり見えた。鴉
は、勿論、門の上にある死人の肉を、啄みに来るのである。ーー尤も今日は、刻限が遅
いせいか、一羽も見えない。唯、所々、崩れかかった、そうしてその崩れ目に長い草の
はえた石段の上に、鴉の糞(くそ)が、点々と白くこびりついているのが見える。下人
は七段ある石段の一番上の段に洗いざらした紺の襖(あお)の尻を据えて、右の頬に出
来た、大きな面皰(にきび)を気にしながら、ぼんやり、雨のふるのを眺めているので
ある。
 作者はさっき、「下人が雨やみを待っていた」と書いた。しかし、下人は、雨がやん
でも格別どうしようと云う当てはない。ふだんなら、勿論、主人の家へ帰る可き筈であ
る。所がその主人からは、四五日前に暇を出された。前にも書いたように、当時京都の
町は一通りならず衰微していた。今この下人が、永年、使われていた主人から暇を出さ
れたのも、この衰微の小さな余波に外ならない。だから、「下人が雨やみを待っていた」
と云うよりも、「雨にふりこめられた下人が、行き所がなくて、途方にくれていた」と
云う方が、適当である。その上、今日の空模様も少なからずこの平安朝の下人の
Sentimentalismeに影響した。申さるの刻下がりからふり出した雨は、未だに上
がるけしきがない。そこで、下人は、何を措いても差当たり明日の暮しをどうにかしよ
うとしてーー云わばどうにもならない事を、どうにかしようとして、とりとめもない考
えをたどりながら、さっきから朱雀大路にふる雨の音を聞くともなく聞いていた。
 雨は羅生門をつつんで、遠くから、ざあっと云う音をあつめてくる。夕闇は次第に空
を低くして、見上げると、門の屋根が、斜めにつき出した甍(いらか)の先に、重たく
うす暗い雲を支えている。
 どうにもならない事を、どうにかする為には、手段を選んでいる遑(いとま)はない。
選んでいれば、築地(ついじ)の下か、道ばたの土の上で、饑死(うえじに)をするば
かりである。そうして、この門の上へ持って来て、犬のように捨てられてしまうばかり
である。選ばないとすればーー下人の考えは、何度も同じ道を低徊した揚句に、やっと
この局所へ逢着した。しかしこの「すれば」は、いつもでたっても、結局「すれば」で
あった。下人は、手段を選ばないという事を肯定しながらも、この「すれば」のかたを
つける為に、当然、この後に来る可き「盗人になるより外に仕方がない」と云う事を、
積極的に肯定するだけの、勇気が出ずにいたのである。
 下人は大きな嚏(くさめ)をして、それから、大儀そうに立上がった。夕冷えのする
京都は、もう火桶が欲しい程の寒さである。風は門の柱と柱との間を、夕闇と共に遠慮
なく、吹きぬける。丹塗の柱にとまっていたきりぎりすも、もうどこかへ行ってしまっ
た。
 下人は、頸をちぢめながら、山吹の汗衫(かざみ)に重ねた、紺の襖の肩を高くして
門のまわりを見まわした。雨風の患のない、人目にかかる惧のない、一晩楽にねられそ
うな所があれば、そこでともかくも、夜を明かそうと思ったからである。すると、幸門
の上の楼へ上る、幅の広い、之も丹を塗った梯子が眼についた。上なら、人がいたにし
ても、どうせ死人ばかりである。下人は、そこで腰にさげた聖柄(ひじりづか)の太刀
が鞘走らないように気をつけながら、藁草履をはいた足を、その梯子の一番下の段へふ
みかけた。
 それから、何分かの後である。羅生門の楼の上へ出る、幅の広い梯子の中段に、一人
の男が、猫のように身をちぢめて、息を殺しながら、上の容子を窺っていた。楼の上か
らさす火の光が、かすかに、その男の右の頬をぬらしている。短い鬚(ひげ)の中に、
赤く膿を持った面皰のある頬である。下人は、始めから、この上にいる者は、死人ばか
りだと高を括っていた。それが、梯子を二三段上って見ると、上では誰か火をとぼして、
しかもその火を其処此処と動かしているらしい。これは、その濁った、黄いろい光が、
隅々に蜘蛛の巣をかけた天井裏に、ゆれながら映ったので、すぐにそれと知れたのであ
る。この雨の夜に、この羅生門の上で、火をともしているからは、どうせ唯の者ではな
い。
 下人は、宮守(やもり)のように足音をぬすんで、やっと急な梯子を、一番上の段ま
で這うようにして上りつめた。そうして体を出来るだけ、平にしながら、頸を出来るだ
け、前へ出して、恐る恐る、楼の内を覗いて見た。
 見ると、楼の内には、噂に聞いた通り、幾つかの屍骸(しがい)が、無造作に棄てて
あるが、火の光の及ぶ範囲が、思ったより狭いので、数は幾つともわからない。唯、お
ぼろげながら、知れるのは、その中に裸の屍骸と、着物を着た屍骸とがあると云う事で
ある。勿論、中には女も男もまじっているらしい。そうして、その屍骸は皆、それが、
嘗(かつて)、生きていた人間だと云う事実さえ疑われる程、土を捏ねて造った人形の
ように、口を開いたり、手を延ばしたりして、ごろごろ床の上にころがっていた。しか
も、肩とか胸とかの高くなっている部分に、ぼんやりした火の光をうけて、低くなって
いる部分の影を一層暗くしながら、永久に唖(おし)の如く黙っていた。
 下人は、それらの屍骸の腐爛した臭気に思わず、鼻を掩った(おおった)。しかし、
その手は、次の瞬間には、もう鼻を掩う事を忘れていた。或る強い感情が殆悉(ほとん
どことごとく)この男の嗅覚を奪ってしまったからである。
 下人の眼は、その時、はじめて、其屍骸の中に蹲っている(うずくまっている)人間
を見た。檜肌色(ひはだいろ)の着物を著た、背の低い、痩せた、白髪頭の、猿のよう
な老婆である。その老婆は、右の手に火をともした松の木片を持って、その屍骸の一つ
の顔を覗きこむように眺めていた。髪の毛の長い所を見ると、多分女の屍骸であろう。
 下人は、六分の恐怖と四分の好奇心とに動かされて、暫時は呼吸(いき)をするのさ
え忘れていた。旧記の記者の語を借りれば、「頭身(とうしん)の毛も太る」ように感
じたのである。すると、老婆は、松の木片を、床板の間に挿して、それから、今まで眺
めていた屍骸の首に両手をかけると、丁度、猿の親が猿の子の虱(しらみ)をとるよう
に、その長い髪の毛を一本ずつ抜きはじめた。髪は手に従って抜けるらしい。
 その髪の毛が、一本ずつ抜けるのに従って下人の心からは、恐怖が少しずつ消えて行っ
た。そうして、それと同時に、その老婆に対するはげしい憎悪が、少しずつ動いて来た。
いや、この老婆に対すると云っては、語弊があるかも知れない。寧(むしろ)、あらゆ
る悪に対する反感が、一分毎に強さを増して来たのである。この時、誰かがこの下人に、
さっき門の下でこの男が考えていた、饑死(うえじに)をするか盗人になるかと云う問
題を、改めて持出したら、恐らく下人は、何の未練もなく、饑死を選んだ事であろう。
それほど、この男の悪を憎む心は、老婆の床に挿した松の木片のように、勢よく燃え上
がりだしていたのである。
 下人には、勿論、何故老婆が死人の髪の毛を抜くかわからなかった。従って、合理的
には、それを善悪の何れに片づけてよいか知らなかった。しかし下人にとっては、この
雨の夜に、この羅生門の上で、死人の髪の毛を抜くと云う事が、それだけで既に許す可
らざる悪であった。勿論 下人は さっき迄自分が、盗人になる気でいた事なぞは と
うに忘れているのである。
 そこで、下人は、両足に力を入れて、いかなり、梯子から上へ飛び上がった そうし
て聖柄(ひじりづか)の太刀に手をかけながら、大股に老婆の前へ歩みよった。老婆が
驚いたのは 云う迄もない。
 老婆は、一目下人を見ると、まるで弩(いしゆみ)にでも弾かれたように 飛び上がっ
た。
 「おのれ、どこへ行く。」
 下人は、老婆が屍骸につまづきながら、慌てふためいて逃げようとする行手を塞いで、
こう罵った。老婆は、それでも下人をつきのけて行こうとする。下人は又、それを行か
すまいとして、押しもどす。二人は屍骸の中で、暫、無言のまま、つかみ合った。しか
し勝負は、はじめから、わかっている。下人はとうとう、老婆の腕をつかんで、無理に
そこへねじ倒した。丁度、鶏(とり)の脚のような、骨と皮ばかりの腕である。
 「何をしていた。さあ何をしていた。云え。云わぬと これだぞよ。」
 下人は、老婆をつき放すと、いきなり、太刀の鞘を払って、白い鋼(はがね)の色を
その眼の前へつきつけた。けれども、老婆は黙っている。両手をわなわなふるわせて、
肩で息を切りながら、眼を、眼球がまぶたの外へ出そうになる程、見開いて、唖のよう
に執拗(しゅうね)く黙っている。これを見ると、下人は始めて明白にこの老婆の生死
が、全然、自分の意志に支配されていると云う事を意識した。そうして、この意識は、
今まではげしく燃えていた憎悪の心を何時(いつ)の間にか冷ましてしまった。後に残っ
たのは、唯、或仕事をして、それが円満に成就した時の、安らかな得意と満足とがある
ばかりである。そこで、下人は、老婆を、見下げながら、少し声を柔げてこう云った。
 「己は検非違使(けびいし)の庁の役人などではない。今し方この門の下を通りかかっ
た旅の者だ。だからお前に縄をかけて、どうしようと云うような事はない。唯今時分、
この門の上で、何をしていたのだか、それを己に話さえすればいいのだ。」
 すると、老婆は、見開いた眼を、一層大きくして、じっとその下人の顔を見守った。
まぶたの赤くなった、肉食鳥のような、鋭い眼で見たのである。それから、皺で、殆、
鼻と一つになった唇を何か物でも噛んでいるように動かした。細い喉で、尖った喉仏の
動いているのが見える。その時、その喉から、鴉(からす)の啼くような声が、喘ぎ喘
ぎ、下人の耳へ伝わって来た。
 「この髪を抜いてな、この女の髪を抜いてな、鬘(かつら)にしようと思うたの
じゃ。」
 下人は、老婆の答が存外、平凡なのに失望した。そうして失望すると同時に、又前の
憎悪が、冷な侮蔑と一しょに、心の中へはいって来た。すると その気色(けしき)が、
先方へも通じたのであろう。老婆は、片手に、まだ屍骸の頭から奪(と)った長い抜け
毛を持ったなり、蟇(ひき)のつぶやくような声で、口ごもりながら、こんな事を云っ
た。
 成程、死人の髪の毛を抜くと云う事は、悪い事かね知れぬ。しかし、こう云う死人の
多くは、皆 その位な事を、されてもいい人間ばかりである。現に、自分が今、髪を抜
いた女などは、蛇を四寸ばかりずつに切って干したのを、干魚(ほしうお)だと云って、
太刀帯(たちはき)の陣へ売りに行った。疫病にかかって死ななかったなら、今でも売
りに行っていたかもしれない。しかも、この女の売る干魚は、味がよいと云うので、太
刀帯たちが、欠かさず菜料に買っていたのである。自分は、この女のした事が悪いとは
思わない。しなければ、饑死(えうじに)をするので、仕方がなくした事だからである。
だから、又今、自分のしていた事も悪い事とは思わない。これもやはりしなければ、饑
死をするので、仕方がなくする事だからである。そうして、その仕方がない事を、よく
知っていたこの女は、自分のする事を許してくれるのにちがいないと思うからであ
る。ーー老婆は、大体こんな意味の事を云った。
 下人は、太刀を鞘におさめて、その太刀の柄を左の手でおさえながら、冷然として、
この話を聞いていた。勿論、 右の手では、赤く頬に膿を持た大きな面皰(にきび)を
気にしながら、聞いているのである。しかし、之を聞いている中に、下人の心には、或
勇気が生まれて来た。それは さっき、門の下でこの男に欠けていた勇気である。そう
して、又さっき、この門の上へ上(あが)って、その老婆を捕えた時の勇気とは、全然、
反対な方向に動こうとする勇気である。下人は、饑死をするか盗人になるかに迷わなかっ
たばかりではない。その時のこの男の心もちから云えば、饑死などと云う事は、殆、考
える事さえ出来ない程、意識の外に追い出されていた。
 「きっと、そうか。」
 老婆の話が完ると、下人は嘲(あざけ)るような声で念を押した。そうして、一足前
へ出ると、不意に、右の手を面皰から離して、老婆の襟上(えりがみ)をつかみながら、
こう云った。
 「では、己が引剥(ひはぎ)をしようと恨むまいな。己もそうしなければ、饑死をす
る体なのだ。」
 下人は、すばやく、老婆の着物を剥ぎとった。それから、足にしがみつこうとする老
婆を、手荒く屍骸の上へ蹴倒した。梯子の口までは、僅に五歩を数えるばかりである。
下人は、剥ぎとった桧肌色の着物をわきにかかえて、またたく間に急な梯子を夜の底へ
かけ下りた。
 暫、死んだように倒れていた老婆が、屍骸の中から、その裸の体を起こしたのは、そ
れから間もなくの事である。老婆は、つぶやくような、うめくような声を立てながら、
まだ燃えている火の光をたよりに、梯子の口まで、這って行った。そうして、そこから、
短い白髪を倒(さかさま)にして、門の下を覗きこんだ。外には、唯、黒洞々(こくと
うとう)たる夜があるばかりである。
 下人は、既に、雨を冒して、京都の町へ強盗を働きに急いでいた。

View File

@ -0,0 +1,107 @@
This file was derived from
http://www.gutenberg.org/files/23864/23864-0.txt
after converting from Traditional Chinese to Simplified Chinese.
--------
~{J<<F5ZR;~}
~{KoWST;#:1xU_#,9zV.4sJB#,K@IzV.5X#,4fMvV.5@#,2;?I2;2lR2!#~}
~{9J>-V.RTNeJB#,P#V.RT<F#,6xKwFdGi#:R;T;5@#,6~T;Ll#,H}T;5X#,KDT;=+#,NeT;7(!#~}
~{5@U_#,AnCqSkIOM,Rb#,?ISkV.K@#,?ISkV.Iz#,6x2;N7N#R2#;LlU_#,RuQt!":.Jn!"J1VFR2#;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inese to Simplified Chinese.
--------
始计第一
孙子曰:兵者,国之大事,死生之地,存亡之道,不可不察也。
故经之以五事,校之以计,而索其情:一曰道,二曰天,三曰地,四曰将,五曰法。
道者,令民与上同意,可与之死,可与之生,而不畏危也;天者,阴阳、寒暑、时制也;地者,远近、险易、广狭、死生也;将者,智、信、仁、勇、严也;法者,曲制、官道、主用也。凡此五者,将莫不闻,知之者胜,不知者不胜。
故校之以计,而索其情,曰:主孰有道?将孰有能?天地孰得?法令孰行?兵?孰强?士卒孰练?赏罚孰明?吾以此知胜负矣。
将听吾计,用之必胜,留之;将不听吾计,用之必败,去之。
计利以听,乃?之势,以佐其外。势者,因利而制权也。
兵者,诡道也。故能而示之不能,用而示之不用,近而示之远,远而示之近。利而诱之,乱而取之,实而备之,强而避之,怒而挠之,卑而骄之,佚而劳之,亲而离之,攻其无备,出其不意。此兵家之胜,不可先传也。
夫未战而庙算胜者,得算多也;未战而庙算不胜者,得算少也。多算胜,少算不胜,而况无算乎!吾以此观之,胜负见矣。
作战第二
孙子曰:凡用兵之法,驰车千?,革车千乘,带甲十万,千里馈粮。则内外之费,宾客之用,胶漆之材,车甲之奉,日费千金,然后十万之师举矣。
其用战也,贵胜,久则钝兵挫锐,攻城则力屈,久暴师则国用不足。夫钝兵挫锐,屈力?货,则诸侯乘其弊而起,虽有智者,不能善其后矣。故兵闻拙速,未睹巧之久也。夫兵久而国利者,未之有也。故不尽知用兵之害者,则不能尽知用兵之利也。
善用兵者,役不再籍,粮不三载,取用於国,因粮於敌,故军食可足也。国之贫於师者远输,远输则百姓贫;近於师者贵卖,贵卖则百姓竭,财竭则急於丘役。力屈财?,中原内虚於家,百姓之费,十去其七;公家之费,破军罢马,甲胄矢弩,戟?矛?,丘牛大车,十去其六。
故智将务食於敌,食敌一钟,当吾二十钟;萁秆一石,当吾二十石。故杀敌者,怒也;取敌之利者,货也。故车战,得车十乘以上,赏其先得者,而更其旌旗。车杂而乘之,卒善而养之,是谓胜敌而益强。
故兵贵胜,不贵久。故知兵之将,民之司命。国家安危之主也。
谋攻第三
孙子曰:凡用兵之法,全国?上,破国次之;全军?上,破军次之;全旅?上,破旅次之;全卒?上,破卒次之;全伍?上,破伍次之。是故百战百胜,非善之善者也;不战而屈人之兵,善之善者也。
故上兵伐谋,其次伐交,其次伐兵,其下攻城。攻城之法,?不得已。修???,具器械,三月而后成;距?,又三月而后已。将不胜其忿,而蚁附之,杀士三分之一,而城不拔者,此攻之灾也。
故善用兵者,屈人之兵,而非战也,拔人之城而非攻也,毁人之国而非久也,必以全争於天下,故兵不顿而利可全,此谋攻之法也。
故用兵之法,十则围之,五则攻之,倍则分之,敌则能战之,少则能逃之,不若则能避之。故小敌之坚,大敌之擒也。
夫将者,国之辅也。辅周则国必强,辅隙则国必弱。故君之所以患於军者三:不知军之不可以进而谓之进,不知军之不可以退而谓之退,是谓縻军;不知三军之事,而同三军之政,则军士惑矣;不知三军之权,而同三军之任,则军士疑矣。三军既惑且疑,则诸侯之难至矣。是谓乱军引胜。
故知胜有五:知可以战与不可以战者,胜。识?寡之用者,胜。上下同欲者,胜。以虞待不虞者,胜。将能而君不御者,胜。此五者,知胜之道也。
故曰:知己知彼,百战不?;不知彼而知己,一胜一负;不知彼不知己,每战必败。
军形第四
孙子曰:昔之善战者,先?不可胜,以待敌之可胜。不可胜在己,可胜在敌。故善战者,能?不可胜,不能使敌必可胜。故曰:胜可知,而不可?。
不可胜者,守也;可胜者,攻也。守则不足,攻则有?。善守者,藏於九地之下,善攻者,动於九天之上,故能自保而全胜也。
见胜不过?人之所知,非善之善者也;战胜而天下曰善,非善之善者也。故举秋毫不?多力,见日月不?明目,闻雷霆不?聪耳。古之善战者,胜於易胜者也。故善战者之胜也,无智名,无勇功,故其战胜不忒。不忒者,其所措必胜,胜已败者也。故善战者,先立於不败之地,而不失敌之败也。是故胜兵先胜,而后求战,败兵先战而后求胜。善用兵者,修道而保法,故能?胜败之政。
兵法:一曰度,二曰量,三曰数,四曰称,五曰胜。地生度,度生量,量生数,数生称,称生胜。故胜兵若以?称?,败兵若以?称?。胜者之战,若决积水於千仞之?者,形也。
兵势第五
孙子曰:凡治?如治寡,分数是也;斗?如斗寡,形名是也;三军之?,可使必受敌而无败者,奇正是也;兵之所加,如以?投卵者,虚实是也。
凡战者,以正合,以奇胜。故善出奇者,无穷如天地,不竭如江海。终而复始,日月是也。死而?生,四时是也。声不过五,五声之变,不可胜听也;色不过五,五色之变,不可胜观也;味不过五,五味之变,不可胜尝也;战势,不过奇正,奇正之变,不可胜穷也。奇正相生,如循环之无端,熟能穷之哉?
激水之疾,至於漂石者,势也;?鸟之疾,至於毁折者,节也。是故善战者,其势险,其节短。势如张弩,节如发机。
纷纷??,斗乱而不可乱也;浑浑沌沌,形圆而不可败也。乱生於治,怯生於勇,弱生於强。治乱,数也;勇怯,势也;强弱,形也。故善动敌者,形之,敌必从之;予之,敌必取之。以利动之,以卒待之。
故善战者,求之於势,不责於人;故能择人而任势。任势者,其战人也,如转木石。木石之性,安则静,危则动,方则止,圆则行。故善战人之势,如转圆石於千仞之山者,势也。
虚实第六
孙子曰:凡先处战地而待敌者佚,后处战地而趋战者劳。
故善战者,致人而不致於人。能使敌人自至者,利之也;能使敌人不得至者,害之也。故敌佚能劳之,饱能饥之,安能动之。出其所必趋,趋其所不意。行千里而不劳者,行於无人之地也;攻而必取者,攻其所不守也。守而必固者,守其所不攻也。
故善攻者,敌不知其所守;善守者,敌不知其所攻。微乎微乎,至於无形;神乎神乎,至於无声,故能?敌之司命。进而不可御者,冲其虚也;退而不可追者,速而不可及也。故我欲战,敌虽高垒深沟,不得不与我战者,攻其所必救也;我不欲战,虽画地而守之,敌不得与我战者,乖其所之也。故形人而我无形,则我专而敌分。我专?一,敌分?十,是以十攻其一也。则我?敌寡,能以?击寡者,则吾之所与战者约矣。吾所与战之地不可知,不可知则敌所备者多,敌所备者多,则吾所与战者寡矣。故备前则后寡,备后则前寡,备左则右寡,备右则左寡,无所不备,则无所不寡。寡者,备人者也;?者,使人备己者也。故知战之地,知战之日,则可千里而会战;不知战之地,不知战日,则左不能救右,右不能救左,前不能救后,后不能救前,而况远者数十里,近者数里乎!以吾度之,越人之兵虽多,亦奚益於胜哉!故曰:胜可?也。敌虽?,可使无斗。故策之而知得失之计,候之而知动静之理,形之而知死生之地,角之而知有?不足之处。故形兵之极,至於无形。无形则深间不能窥,智者不能谋。因形而措胜於??不能知。人皆知我所以胜之形,而莫知吾所以制胜之形。故其战胜不?,而应形於无穷。夫兵形象水,水之行避高而趋下,兵之形避实而击虚;水因地而制流,兵因敌而制胜。故兵无常势,水无常形。能因敌变化而取胜者,谓之神。故五行无常胜,四时无常位,日有短长,月有死生。
军争第七
孙子曰: 凡用兵之法,将受命於君,合军聚?,交和而舍,莫难於军争。军争之难者,以迂?直,以患?利。故迂其途,而诱之以利,后人发,先人至,此知迂直之计者也。军争?利,军争?危。举军而争利则不及,委军而争利则?重捐。是故?甲而趋,日夜不处,倍道兼行,百?而争利,则擒三将军,劲者先,疲者后,其法十一而至;五十里而争利,则蹶上将军,其法半至;三十里而争利,则三分之二至。是故军无?重则亡,无粮食则亡,无委积则亡。故不知诸侯之谋者,不能豫交;不知山林、险阻、沮泽之形者,不能行军;不用乡导者,不能得地利。故兵以诈立,以利动,以分和?变者也。故其疾如风,其徐如林,侵掠如火,不动如山,难知如阴,动如雷震。掠乡分?,廓地分利,悬权而动。先知迂直之计者胜,此军争之法也。《军政》曰:“言不相闻,故?之金鼓;视不相见,故?之旌旗。”夫金鼓旌旗者,所以一民之耳目也。民既专一,则勇者不得独进,怯者不得独退,此用?之法也。故夜战多金鼓,昼战多旌旗,所以变人之耳目也。三军可夺气,将军可夺心。是故朝气锐,昼气惰,暮气归。善用兵者,避其锐气,击其惰归,此治气者也。以治待乱,以静待哗,此治心者也。以近待远,以佚待劳,以饱待饥,此治力者也。无邀正正之旗,无击堂堂之陈,此治变者也。故用兵之法,高陵勿向,背丘勿逆,佯北勿从,锐卒勿攻,饵兵勿食,归师勿遏,围师遗?,穷寇勿迫,此用兵之法也。
九变第八
孙子曰: 凡用兵之法,将受命於君,合军聚合。泛地无舍,衢地合交,绝地无留,围地则谋,死地则战,途有所不由,军有所不击,城有所不攻,地有所不争,君命有所不受。故将通於九变之利者,知用兵矣;将不通九变之利,虽知地形,不能得地之利矣;治兵不知九变之术,虽知五利,不能得人之用矣。是故智者之虑,必杂於利害,杂於利而务可信也,杂於害而患可解也。是故屈诸侯者以害,役诸侯者以业,趋诸侯者以利。故用兵之法,无恃其不来,恃吾有以待之;无恃其不攻,恃吾有所不可攻也。故将有五危,必死可杀,必生可虏,忿速可侮,廉洁可辱,爱民可烦。凡此五者,将之过也,用兵之灾也。覆军杀将,必以五危,不可不察也。
行军第九
孙子曰:凡处军相敌,绝山依?,视生处高,战隆无登,此处山之军也。绝水必远水,客绝水而来,勿迎之於水内,令半渡而击之利,欲战者,无附於水而迎客,视生处高,无迎水流,此处水上之军也。绝斥泽,唯亟去无留,若交军於斥泽之中,必依水草而背?树,此处斥泽之军也。平陆处易,右背高,前死后生,此处平陆之军也。凡此四军之利,黄帝之所以胜四帝也。凡军好高而恶下,贵阳而贱阴,养生而处实,军无百疾,是谓必胜。丘陵堤防,必处其阳而右背之,此兵之利,地之助也。上雨水流至,欲涉者,待其定也。凡地有绝涧、天井、天牢、天罗、天陷、天隙,必亟去之,勿近也。吾远之,敌近之;吾迎之,敌背之。军旁有险阻、潢井、蒹葭、小林、??者,必谨覆索之,此伏?之所处也。敌近而静者,恃其险也;远而挑战者,欲人之进也;其所居易者,利也;?树动者,来也;?草多障者,疑也;鸟起者,伏也;兽骇者,覆也;尘高而锐者,车来也;卑而广者,徒来也;散而条达者,樵?也;少而往来者,营军也;辞卑而备者,进也;辞强而进驱者,退也;轻车先出居其侧者,陈也;无约而请和者,谋也;奔走而陈兵者,期也;半进半退者,诱也;杖而立者,饥也;汲而先饮者,渴也;见利而不进者,劳也;鸟集者,虚也;夜呼者,恐也;军扰者,将不重也;旌旗动者,乱也;吏怒者,倦也;杀马肉食者,军无粮也;悬?不返其舍者,穷寇也;谆谆翕翕,徐与人言者,失?也;数赏者,窘也;数罚者,困也;先暴而后畏其?者,不精之至也;来委谢者,欲休息也。兵怒而相迎,久而不合,又不相去,必谨察之。兵非贵益多也,惟无武进,足以并力料敌取人而已。夫惟无虑而易敌者,必擒於人。卒未亲而罚之,则不服,不服则难用。卒已亲附而罚不行,则不可用。故合之以文,齐之以武,是谓必取。令素行以教其民,则民服;令素不行以教其民,则民不服。令素行者,与?相得也。
地形第十
孙子曰:地形有通者、有?者、有支者、有隘者、有险者、有远者。我可以往,彼可以来,曰通。通形者,先居高阳,利粮道,以战则利。可以往,难以返,曰?。?形者,敌无备,出而胜之,敌若有备,出而不胜,难以返,不利。我出而不利,彼出而不利,曰支。支形者,敌虽利我,我无出也,引而去之,令敌半出而击之利。隘形者,我先居之,必盈之以待敌。若敌先居之,盈而勿从,不盈而从之。险形者,我先居之,必居高阳以待敌;若敌先居之,引而去之,勿从也。远形者,势均难以挑战,战而不利。凡此六者,地之道也,将之至任,不可不察也。凡兵有走者、有驰者、有陷者、有崩者、有乱者、有北者。凡此六者,非天地之灾,将之过也。夫势均,以一击十,曰走;卒强吏弱,曰驰;吏强卒弱,曰陷;大吏怒而不服,遇敌?而自战,将不知其能,曰崩;将弱不严,教道不明,吏卒无常,陈兵纵横,曰乱;将不能料敌,以少合?,以弱击强,兵无选锋,曰北。凡此六者,败之道也,将之至任,不可不察也。夫地形者,兵之助也。料敌制胜,计险隘远近,上将之道也。知此而用战者必胜,不知此而用战者必败。故战道必胜,主曰无战,必战可也;战道不胜,主曰必战,无战可也。故进不求名,退不避罪,唯民是保,而利於主,国之宝也。视卒如婴儿,故可以与之赴深溪;视卒如爱子,故可与之俱死。厚而不能使,爱而不能令,乱而不能治,譬若骄子,不可用也。知吾卒之可以击,而不知敌之不可击,胜之半也;知敌之可击,而不知吾卒之不可以击,胜之半也;知敌之可击,知吾卒之可以击,而不知地形之不可以战,胜之半也。故知兵者,动而不迷,举而不穷。故曰:知彼知己,胜乃不殆;知天知地,胜乃可全。
九地第十一
孙子曰:用兵之法,有散地,有轻地,有争地,有交地,有衢地,有重地,有泛地,有围地,有死地。诸侯自战其地者,?散地;入人之地不深者,?轻地;我得亦利,彼得亦利者,?争地;我可以往,彼可以来者,?交地;诸侯之地三属,先至而得天下?者,?衢地;入人之地深,背城邑多者,?重地;山林、险阻、沮泽,凡难行之道者,?泛地;所由入者隘,所从归者迂,彼寡可以击吾之?者,?围地;疾战则存,不疾战则亡者,?死地。是故散地则无战,轻地则无止,争地则无攻,交地则无绝,衢地则合交,重地则掠,泛地则行,围地则谋,死地则战。古之善用兵者,能使敌人前后不相及,?寡不相恃,贵贱不相救,上下不相收,卒离而不集,兵合而不齐。合於利而动,不合於利而止。敢问敌?而整将来,待之若何曰:先夺其所爱则听矣。兵之情主速,乘人之不及。由不虞之道,攻其所不戒也。凡?客之道,深入则专。主人不克,掠於饶野,三军足食。谨养而勿劳,并气积力,运兵计谋,?不可测。投之无所往,死且不北。死焉不得,士人尽力。兵士甚陷则不惧,无所往则固,深入则拘,不得已则斗。是故其兵不修而戒,不求而得,不约而亲,不令而信,禁祥去疑,至死无所之。吾士无?财,非恶货也;无?命,非恶寿也。令发之日,士卒坐者涕沾襟,偃卧者涕交颐,投之无所往,诸、?之勇也。故善用兵者,譬如率然。率然者,常山之蛇也。击其首则尾至,击其尾则首至,击其中则首尾俱至。敢问兵可使如率然乎?曰可。夫吴人与越人相恶也,当其同舟而济而遇风,其相救也如左右手。是故方马埋轮,未足恃也;齐勇如一,政之道也;刚柔皆得,地之理也。故善用兵者,携手若使一人,不得已也。将军之事,静以幽,正以治,能愚士卒之耳目,使之无知;易其事,革其谋,使人无识;易其居,迂其途,使民不得虑。帅与之期,如登高而去其梯;帅与之深入诸侯之地,而发其机。若驱群羊,驱而往,驱而来,莫知所之。聚三军之?,投之於险,此谓将军之事也。九地之变,屈伸之力,人情之理,不可不察也。凡?客之道,深则专,浅则散。去国越境而师者,绝地也;四彻者,衢地也;入深者,重地也;入浅者,轻地也;背固前隘者,围地也;无所往者,死地也。是故散地吾将一其志,轻地吾将使之属,争地吾将趋其后,交地吾将谨其守,交地吾将固其结,衢地吾将谨其恃,重地吾将继其食,泛地吾将进其途,围地吾将塞其?,死地吾将示之以不活。故兵之情:围则御,不得已则斗,过则从。是故不知诸侯之谋者,不能预交;不知山林、险阻、沮泽之形者,不能行军;不用乡导,不能得地利。四五者,一不知,非霸王之兵也。夫霸王之兵,伐大国,则其?不得聚;威加於敌,则其交不得合。是故不争天下之交,不养天下之权,信己之私,威加於敌,则其城可拔,其国可隳。施无法之赏,悬无政之令。犯三军之?,若使一人。犯之以事,勿告以言;犯之以害,勿告以利。投之亡地然后存,陷之死地然后生。夫?陷於害,然后能?胜败。故?兵之事,在顺详敌之意,并敌一向,千里杀将,是谓巧能成事。是故政举之日,夷关折符,无通其使,厉於廊庙之上,以诛其事。敌人开?,必亟入之,先其所爱,微与之期,践墨随敌,以决战事。是故始如处女,敌人开户;后如脱兔,敌不及拒。
火攻第十二
孙子曰:凡火攻有五:一曰火人,二曰火积,三曰火?,四曰火库,五曰火队。行火必有因,因必素具。发火有时,起火有日。时者,天之燥也。日者,月在箕、壁、翼、?也。凡此四宿者,风起之日也。凡火攻,必因五火之变而应之:火发於内,则早应之於外;火发而其兵静者,待而勿攻,极其火力,可从而从之,不可从则上。火可发於外,无待於内,以时发之,火发上风,无攻下风,昼风久,夜风止。凡军必知五火之变,以数守之。故以火佐攻者明,以水佐攻者强。水可以绝,不可以夺。夫战胜攻取而不惰其功者凶,命曰“费留”。故曰:明主虑之,良将惰之,非利不动,非得不用,非危不战。主不可以怒而兴师,将不可以?而攻战。合於利而动,不合於利而上。怒可以复喜,?可以复说,亡国不可以复存,死者不可以复生。故明主慎之,良将警之。此安国全军之道也。
用间第十三
孙子曰: 凡兴师十万,出征千里,百姓之费,公家之奉,日费千金,内外骚动,怠於道路,不得操事者,七十万家。相守数年,以争一日之胜,而爱爵禄百金,不知敌之情者,不仁之至也,非民之将也,非主之佐也,非胜之主也。故明君贤将所以动而胜人,成功出於?者,先知也。先知者,不可取於鬼神,不可象於事,不可验於度,必取於人,知敌之情者也。故用间有五:有因间,有内间,有反间,有死间,有生间。五间俱起,莫知其道,是谓神纪,人君之宝也。乡间者,因其乡人而用之;内间者,因其官人而用之;反间者,因其敌间而用之;死间者,??事於外,令吾闻知之而传於敌间也;生间者,反报也。故三军之事,莫亲於间,赏莫厚於间,事莫密於间,非圣贤不能用间,非仁义不能使间,非微妙不能得间之实。微哉微哉!无所不用间也。间事未发而先闻者,间与所告者兼死。凡军之所欲击,城之所欲攻,人之所欲杀,必先知其守将、左右、?者、门者、舍人之姓名,令吾间必索知之。敌间之来间我者,因而利之,导而舍之,故反间可得而用也;因是而知之,故乡间、内间可得而使也;因是而知之,故死间??事,可使告敌;因是而知之,故生间可使如期。五间之事,主必知之,知之必在於反间,故反间不可不厚也。昔殷之兴也,伊挚在夏;周之兴也,吕牙在殷。故明君贤将,能以上智?间者,必成大功。此兵之要,三军之所恃而动也。

View File

@ -0,0 +1,107 @@
This file was derived from
http://www.gutenberg.org/files/23864/23864-0.txt
after converting from Traditional Chinese to Simplified Chinese.
--------
始计第一
孙子曰:兵者,国之大事,死生之地,存亡之道,不可不察也。
故经之以五事,校之以计,而索其情:一曰道,二曰天,三曰地,四曰将,五曰法。
道者,令民与上同意,可与之死,可与之生,而不畏危也;天者,阴阳、寒暑、时制也;地者,远近、险易、广狭、死生也;将者,智、信、仁、勇、严也;法者,曲制、官道、主用也。凡此五者,将莫不闻,知之者胜,不知者不胜。
故校之以计,而索其情,曰:主孰有道?将孰有能?天地孰得?法令孰行?兵眾孰强?士卒孰练?赏罚孰明?吾以此知胜负矣。
将听吾计,用之必胜,留之;将不听吾计,用之必败,去之。
计利以听,乃為之势,以佐其外。势者,因利而制权也。
兵者,诡道也。故能而示之不能,用而示之不用,近而示之远,远而示之近。利而诱之,乱而取之,实而备之,强而避之,怒而挠之,卑而骄之,佚而劳之,亲而离之,攻其无备,出其不意。此兵家之胜,不可先传也。
夫未战而庙算胜者,得算多也;未战而庙算不胜者,得算少也。多算胜,少算不胜,而况无算乎!吾以此观之,胜负见矣。
作战第二
孙子曰:凡用兵之法,驰车千駟,革车千乘,带甲十万,千里馈粮。则内外之费,宾客之用,胶漆之材,车甲之奉,日费千金,然后十万之师举矣。
其用战也,贵胜,久则钝兵挫锐,攻城则力屈,久暴师则国用不足。夫钝兵挫锐,屈力殫货,则诸侯乘其弊而起,虽有智者,不能善其后矣。故兵闻拙速,未睹巧之久也。夫兵久而国利者,未之有也。故不尽知用兵之害者,则不能尽知用兵之利也。
善用兵者,役不再籍,粮不三载,取用於国,因粮於敌,故军食可足也。国之贫於师者远输,远输则百姓贫;近於师者贵卖,贵卖则百姓竭,财竭则急於丘役。力屈财殫,中原内虚於家,百姓之费,十去其七;公家之费,破军罢马,甲胄矢弩,戟楯矛櫓,丘牛大车,十去其六。
故智将务食於敌,食敌一钟,当吾二十钟;萁秆一石,当吾二十石。故杀敌者,怒也;取敌之利者,货也。故车战,得车十乘以上,赏其先得者,而更其旌旗。车杂而乘之,卒善而养之,是谓胜敌而益强。
故兵贵胜,不贵久。故知兵之将,民之司命。国家安危之主也。
谋攻第三
孙子曰:凡用兵之法,全国為上,破国次之;全军為上,破军次之;全旅為上,破旅次之;全卒為上,破卒次之;全伍為上,破伍次之。是故百战百胜,非善之善者也;不战而屈人之兵,善之善者也。
故上兵伐谋,其次伐交,其次伐兵,其下攻城。攻城之法,為不得已。修櫓轒轀,具器械,三月而后成;距闉,又三月而后已。将不胜其忿,而蚁附之,杀士三分之一,而城不拔者,此攻之灾也。
故善用兵者,屈人之兵,而非战也,拔人之城而非攻也,毁人之国而非久也,必以全争於天下,故兵不顿而利可全,此谋攻之法也。
故用兵之法,十则围之,五则攻之,倍则分之,敌则能战之,少则能逃之,不若则能避之。故小敌之坚,大敌之擒也。
夫将者,国之辅也。辅周则国必强,辅隙则国必弱。故君之所以患於军者三:不知军之不可以进而谓之进,不知军之不可以退而谓之退,是谓縻军;不知三军之事,而同三军之政,则军士惑矣;不知三军之权,而同三军之任,则军士疑矣。三军既惑且疑,则诸侯之难至矣。是谓乱军引胜。
故知胜有五:知可以战与不可以战者,胜。识眾寡之用者,胜。上下同欲者,胜。以虞待不虞者,胜。将能而君不御者,胜。此五者,知胜之道也。
故曰:知己知彼,百战不貽;不知彼而知己,一胜一负;不知彼不知己,每战必败。
军形第四
孙子曰:昔之善战者,先為不可胜,以待敌之可胜。不可胜在己,可胜在敌。故善战者,能為不可胜,不能使敌必可胜。故曰:胜可知,而不可為。
不可胜者,守也;可胜者,攻也。守则不足,攻则有餘。善守者,藏於九地之下,善攻者,动於九天之上,故能自保而全胜也。
见胜不过眾人之所知,非善之善者也;战胜而天下曰善,非善之善者也。故举秋毫不為多力,见日月不為明目,闻雷霆不為聪耳。古之善战者,胜於易胜者也。故善战者之胜也,无智名,无勇功,故其战胜不忒。不忒者,其所措必胜,胜已败者也。故善战者,先立於不败之地,而不失敌之败也。是故胜兵先胜,而后求战,败兵先战而后求胜。善用兵者,修道而保法,故能為胜败之政。
兵法:一曰度,二曰量,三曰数,四曰称,五曰胜。地生度,度生量,量生数,数生称,称生胜。故胜兵若以鎰称銖,败兵若以銖称鎰。胜者之战,若决积水於千仞之谿者,形也。
兵势第五
孙子曰:凡治眾如治寡,分数是也;斗眾如斗寡,形名是也;三军之眾,可使必受敌而无败者,奇正是也;兵之所加,如以碫投卵者,虚实是也。
凡战者,以正合,以奇胜。故善出奇者,无穷如天地,不竭如江海。终而复始,日月是也。死而復生,四时是也。声不过五,五声之变,不可胜听也;色不过五,五色之变,不可胜观也;味不过五,五味之变,不可胜尝也;战势,不过奇正,奇正之变,不可胜穷也。奇正相生,如循环之无端,熟能穷之哉?
激水之疾,至於漂石者,势也;鷙鸟之疾,至於毁折者,节也。是故善战者,其势险,其节短。势如张弩,节如发机。
纷纷紜紜,斗乱而不可乱也;浑浑沌沌,形圆而不可败也。乱生於治,怯生於勇,弱生於强。治乱,数也;勇怯,势也;强弱,形也。故善动敌者,形之,敌必从之;予之,敌必取之。以利动之,以卒待之。
故善战者,求之於势,不责於人;故能择人而任势。任势者,其战人也,如转木石。木石之性,安则静,危则动,方则止,圆则行。故善战人之势,如转圆石於千仞之山者,势也。
虚实第六
孙子曰:凡先处战地而待敌者佚,后处战地而趋战者劳。
故善战者,致人而不致於人。能使敌人自至者,利之也;能使敌人不得至者,害之也。故敌佚能劳之,饱能饥之,安能动之。出其所必趋,趋其所不意。行千里而不劳者,行於无人之地也;攻而必取者,攻其所不守也。守而必固者,守其所不攻也。
故善攻者,敌不知其所守;善守者,敌不知其所攻。微乎微乎,至於无形;神乎神乎,至於无声,故能為敌之司命。进而不可御者,冲其虚也;退而不可追者,速而不可及也。故我欲战,敌虽高垒深沟,不得不与我战者,攻其所必救也;我不欲战,虽画地而守之,敌不得与我战者,乖其所之也。故形人而我无形,则我专而敌分。我专為一,敌分為十,是以十攻其一也。则我眾敌寡,能以眾击寡者,则吾之所与战者约矣。吾所与战之地不可知,不可知则敌所备者多,敌所备者多,则吾所与战者寡矣。故备前则后寡,备后则前寡,备左则右寡,备右则左寡,无所不备,则无所不寡。寡者,备人者也;眾者,使人备己者也。故知战之地,知战之日,则可千里而会战;不知战之地,不知战日,则左不能救右,右不能救左,前不能救后,后不能救前,而况远者数十里,近者数里乎!以吾度之,越人之兵虽多,亦奚益於胜哉!故曰:胜可為也。敌虽眾,可使无斗。故策之而知得失之计,候之而知动静之理,形之而知死生之地,角之而知有餘不足之处。故形兵之极,至於无形。无形则深间不能窥,智者不能谋。因形而措胜於眾,眾不能知。人皆知我所以胜之形,而莫知吾所以制胜之形。故其战胜不復,而应形於无穷。夫兵形象水,水之行避高而趋下,兵之形避实而击虚;水因地而制流,兵因敌而制胜。故兵无常势,水无常形。能因敌变化而取胜者,谓之神。故五行无常胜,四时无常位,日有短长,月有死生。
军争第七
孙子曰: 凡用兵之法,将受命於君,合军聚眾,交和而舍,莫难於军争。军争之难者,以迂為直,以患為利。故迂其途,而诱之以利,后人发,先人至,此知迂直之计者也。军争為利,军争為危。举军而争利则不及,委军而争利则輜重捐。是故捲甲而趋,日夜不处,倍道兼行,百裡而争利,则擒三将军,劲者先,疲者后,其法十一而至;五十里而争利,则蹶上将军,其法半至;三十里而争利,则三分之二至。是故军无輜重则亡,无粮食则亡,无委积则亡。故不知诸侯之谋者,不能豫交;不知山林、险阻、沮泽之形者,不能行军;不用乡导者,不能得地利。故兵以诈立,以利动,以分和為变者也。故其疾如风,其徐如林,侵掠如火,不动如山,难知如阴,动如雷震。掠乡分眾,廓地分利,悬权而动。先知迂直之计者胜,此军争之法也。《军政》曰:“言不相闻,故為之金鼓;视不相见,故為之旌旗。”夫金鼓旌旗者,所以一民之耳目也。民既专一,则勇者不得独进,怯者不得独退,此用眾之法也。故夜战多金鼓,昼战多旌旗,所以变人之耳目也。三军可夺气,将军可夺心。是故朝气锐,昼气惰,暮气归。善用兵者,避其锐气,击其惰归,此治气者也。以治待乱,以静待哗,此治心者也。以近待远,以佚待劳,以饱待饥,此治力者也。无邀正正之旗,无击堂堂之陈,此治变者也。故用兵之法,高陵勿向,背丘勿逆,佯北勿从,锐卒勿攻,饵兵勿食,归师勿遏,围师遗闕,穷寇勿迫,此用兵之法也。
九变第八
孙子曰: 凡用兵之法,将受命於君,合军聚合。泛地无舍,衢地合交,绝地无留,围地则谋,死地则战,途有所不由,军有所不击,城有所不攻,地有所不争,君命有所不受。故将通於九变之利者,知用兵矣;将不通九变之利,虽知地形,不能得地之利矣;治兵不知九变之术,虽知五利,不能得人之用矣。是故智者之虑,必杂於利害,杂於利而务可信也,杂於害而患可解也。是故屈诸侯者以害,役诸侯者以业,趋诸侯者以利。故用兵之法,无恃其不来,恃吾有以待之;无恃其不攻,恃吾有所不可攻也。故将有五危,必死可杀,必生可虏,忿速可侮,廉洁可辱,爱民可烦。凡此五者,将之过也,用兵之灾也。覆军杀将,必以五危,不可不察也。
行军第九
孙子曰:凡处军相敌,绝山依穀,视生处高,战隆无登,此处山之军也。绝水必远水,客绝水而来,勿迎之於水内,令半渡而击之利,欲战者,无附於水而迎客,视生处高,无迎水流,此处水上之军也。绝斥泽,唯亟去无留,若交军於斥泽之中,必依水草而背眾树,此处斥泽之军也。平陆处易,右背高,前死后生,此处平陆之军也。凡此四军之利,黄帝之所以胜四帝也。凡军好高而恶下,贵阳而贱阴,养生而处实,军无百疾,是谓必胜。丘陵堤防,必处其阳而右背之,此兵之利,地之助也。上雨水流至,欲涉者,待其定也。凡地有绝涧、天井、天牢、天罗、天陷、天隙,必亟去之,勿近也。吾远之,敌近之;吾迎之,敌背之。军旁有险阻、潢井、蒹葭、小林、蘙薈者,必谨覆索之,此伏姦之所处也。敌近而静者,恃其险也;远而挑战者,欲人之进也;其所居易者,利也;眾树动者,来也;眾草多障者,疑也;鸟起者,伏也;兽骇者,覆也;尘高而锐者,车来也;卑而广者,徒来也;散而条达者,樵採也;少而往来者,营军也;辞卑而备者,进也;辞强而进驱者,退也;轻车先出居其侧者,陈也;无约而请和者,谋也;奔走而陈兵者,期也;半进半退者,诱也;杖而立者,饥也;汲而先饮者,渴也;见利而不进者,劳也;鸟集者,虚也;夜呼者,恐也;军扰者,将不重也;旌旗动者,乱也;吏怒者,倦也;杀马肉食者,军无粮也;悬甀不返其舍者,穷寇也;谆谆翕翕,徐与人言者,失眾也;数赏者,窘也;数罚者,困也;先暴而后畏其眾者,不精之至也;来委谢者,欲休息也。兵怒而相迎,久而不合,又不相去,必谨察之。兵非贵益多也,惟无武进,足以并力料敌取人而已。夫惟无虑而易敌者,必擒於人。卒未亲而罚之,则不服,不服则难用。卒已亲附而罚不行,则不可用。故合之以文,齐之以武,是谓必取。令素行以教其民,则民服;令素不行以教其民,则民不服。令素行者,与眾相得也。
地形第十
孙子曰:地形有通者、有掛者、有支者、有隘者、有险者、有远者。我可以往,彼可以来,曰通。通形者,先居高阳,利粮道,以战则利。可以往,难以返,曰掛。掛形者,敌无备,出而胜之,敌若有备,出而不胜,难以返,不利。我出而不利,彼出而不利,曰支。支形者,敌虽利我,我无出也,引而去之,令敌半出而击之利。隘形者,我先居之,必盈之以待敌。若敌先居之,盈而勿从,不盈而从之。险形者,我先居之,必居高阳以待敌;若敌先居之,引而去之,勿从也。远形者,势均难以挑战,战而不利。凡此六者,地之道也,将之至任,不可不察也。凡兵有走者、有驰者、有陷者、有崩者、有乱者、有北者。凡此六者,非天地之灾,将之过也。夫势均,以一击十,曰走;卒强吏弱,曰驰;吏强卒弱,曰陷;大吏怒而不服,遇敌懟而自战,将不知其能,曰崩;将弱不严,教道不明,吏卒无常,陈兵纵横,曰乱;将不能料敌,以少合眾,以弱击强,兵无选锋,曰北。凡此六者,败之道也,将之至任,不可不察也。夫地形者,兵之助也。料敌制胜,计险隘远近,上将之道也。知此而用战者必胜,不知此而用战者必败。故战道必胜,主曰无战,必战可也;战道不胜,主曰必战,无战可也。故进不求名,退不避罪,唯民是保,而利於主,国之宝也。视卒如婴儿,故可以与之赴深溪;视卒如爱子,故可与之俱死。厚而不能使,爱而不能令,乱而不能治,譬若骄子,不可用也。知吾卒之可以击,而不知敌之不可击,胜之半也;知敌之可击,而不知吾卒之不可以击,胜之半也;知敌之可击,知吾卒之可以击,而不知地形之不可以战,胜之半也。故知兵者,动而不迷,举而不穷。故曰:知彼知己,胜乃不殆;知天知地,胜乃可全。
九地第十一
孙子曰:用兵之法,有散地,有轻地,有争地,有交地,有衢地,有重地,有泛地,有围地,有死地。诸侯自战其地者,為散地;入人之地不深者,為轻地;我得亦利,彼得亦利者,為争地;我可以往,彼可以来者,為交地;诸侯之地三属,先至而得天下眾者,為衢地;入人之地深,背城邑多者,為重地;山林、险阻、沮泽,凡难行之道者,為泛地;所由入者隘,所从归者迂,彼寡可以击吾之眾者,為围地;疾战则存,不疾战则亡者,為死地。是故散地则无战,轻地则无止,争地则无攻,交地则无绝,衢地则合交,重地则掠,泛地则行,围地则谋,死地则战。古之善用兵者,能使敌人前后不相及,眾寡不相恃,贵贱不相救,上下不相收,卒离而不集,兵合而不齐。合於利而动,不合於利而止。敢问敌眾而整将来,待之若何曰:先夺其所爱则听矣。兵之情主速,乘人之不及。由不虞之道,攻其所不戒也。凡為客之道,深入则专。主人不克,掠於饶野,三军足食。谨养而勿劳,并气积力,运兵计谋,為不可测。投之无所往,死且不北。死焉不得,士人尽力。兵士甚陷则不惧,无所往则固,深入则拘,不得已则斗。是故其兵不修而戒,不求而得,不约而亲,不令而信,禁祥去疑,至死无所之。吾士无餘财,非恶货也;无餘命,非恶寿也。令发之日,士卒坐者涕沾襟,偃卧者涕交颐,投之无所往,诸、劌之勇也。故善用兵者,譬如率然。率然者,常山之蛇也。击其首则尾至,击其尾则首至,击其中则首尾俱至。敢问兵可使如率然乎?曰可。夫吴人与越人相恶也,当其同舟而济而遇风,其相救也如左右手。是故方马埋轮,未足恃也;齐勇如一,政之道也;刚柔皆得,地之理也。故善用兵者,携手若使一人,不得已也。将军之事,静以幽,正以治,能愚士卒之耳目,使之无知;易其事,革其谋,使人无识;易其居,迂其途,使民不得虑。帅与之期,如登高而去其梯;帅与之深入诸侯之地,而发其机。若驱群羊,驱而往,驱而来,莫知所之。聚三军之眾,投之於险,此谓将军之事也。九地之变,屈伸之力,人情之理,不可不察也。凡為客之道,深则专,浅则散。去国越境而师者,绝地也;四彻者,衢地也;入深者,重地也;入浅者,轻地也;背固前隘者,围地也;无所往者,死地也。是故散地吾将一其志,轻地吾将使之属,争地吾将趋其后,交地吾将谨其守,交地吾将固其结,衢地吾将谨其恃,重地吾将继其食,泛地吾将进其途,围地吾将塞其闕,死地吾将示之以不活。故兵之情:围则御,不得已则斗,过则从。是故不知诸侯之谋者,不能预交;不知山林、险阻、沮泽之形者,不能行军;不用乡导,不能得地利。四五者,一不知,非霸王之兵也。夫霸王之兵,伐大国,则其眾不得聚;威加於敌,则其交不得合。是故不争天下之交,不养天下之权,信己之私,威加於敌,则其城可拔,其国可隳。施无法之赏,悬无政之令。犯三军之眾,若使一人。犯之以事,勿告以言;犯之以害,勿告以利。投之亡地然后存,陷之死地然后生。夫眾陷於害,然后能為胜败。故為兵之事,在顺详敌之意,并敌一向,千里杀将,是谓巧能成事。是故政举之日,夷关折符,无通其使,厉於廊庙之上,以诛其事。敌人开闔,必亟入之,先其所爱,微与之期,践墨随敌,以决战事。是故始如处女,敌人开户;后如脱兔,敌不及拒。
火攻第十二
孙子曰:凡火攻有五:一曰火人,二曰火积,三曰火輜,四曰火库,五曰火队。行火必有因,因必素具。发火有时,起火有日。时者,天之燥也。日者,月在箕、壁、翼、軫也。凡此四宿者,风起之日也。凡火攻,必因五火之变而应之:火发於内,则早应之於外;火发而其兵静者,待而勿攻,极其火力,可从而从之,不可从则上。火可发於外,无待於内,以时发之,火发上风,无攻下风,昼风久,夜风止。凡军必知五火之变,以数守之。故以火佐攻者明,以水佐攻者强。水可以绝,不可以夺。夫战胜攻取而不惰其功者凶,命曰“费留”。故曰:明主虑之,良将惰之,非利不动,非得不用,非危不战。主不可以怒而兴师,将不可以慍而攻战。合於利而动,不合於利而上。怒可以复喜,慍可以复说,亡国不可以复存,死者不可以复生。故明主慎之,良将警之。此安国全军之道也。
用间第十三
孙子曰: 凡兴师十万,出征千里,百姓之费,公家之奉,日费千金,内外骚动,怠於道路,不得操事者,七十万家。相守数年,以争一日之胜,而爱爵禄百金,不知敌之情者,不仁之至也,非民之将也,非主之佐也,非胜之主也。故明君贤将所以动而胜人,成功出於眾者,先知也。先知者,不可取於鬼神,不可象於事,不可验於度,必取於人,知敌之情者也。故用间有五:有因间,有内间,有反间,有死间,有生间。五间俱起,莫知其道,是谓神纪,人君之宝也。乡间者,因其乡人而用之;内间者,因其官人而用之;反间者,因其敌间而用之;死间者,為誑事於外,令吾闻知之而传於敌间也;生间者,反报也。故三军之事,莫亲於间,赏莫厚於间,事莫密於间,非圣贤不能用间,非仁义不能使间,非微妙不能得间之实。微哉微哉!无所不用间也。间事未发而先闻者,间与所告者兼死。凡军之所欲击,城之所欲攻,人之所欲杀,必先知其守将、左右、謁者、门者、舍人之姓名,令吾间必索知之。敌间之来间我者,因而利之,导而舍之,故反间可得而用也;因是而知之,故乡间、内间可得而使也;因是而知之,故死间為誑事,可使告敌;因是而知之,故生间可使如期。五间之事,主必知之,知之必在於反间,故反间不可不厚也。昔殷之兴也,伊挚在夏;周之兴也,吕牙在殷。故明君贤将,能以上智為间者,必成大功。此兵之要,三军之所恃而动也。

View File

@ -0,0 +1,107 @@
This file was derived from
http://www.gutenberg.org/files/23864/23864-0.txt
after converting from Traditional Chinese to Simplified Chinese.
--------
始计第一
孙子曰:兵者,国之大事,死生之地,存亡之道,不可不察也。
故经之以五事,校之以计,而索其情:一曰道,二曰天,三曰地,四曰将,五曰法。
道者,令民与上同意,可与之死,可与之生,而不畏危也;天者,阴阳、寒暑、时制也;地者,远近、险易、广狭、死生也;将者,智、信、仁、勇、严也;法者,曲制、官道、主用也。凡此五者,将莫不闻,知之者胜,不知者不胜。
故校之以计,而索其情,曰:主孰有道?将孰有能?天地孰得?法令孰行?兵眾孰强?士卒孰练?赏罚孰明?吾以此知胜负矣。
将听吾计,用之必胜,留之;将不听吾计,用之必败,去之。
计利以听,乃為之势,以佐其外。势者,因利而制权也。
兵者,诡道也。故能而示之不能,用而示之不用,近而示之远,远而示之近。利而诱之,乱而取之,实而备之,强而避之,怒而挠之,卑而骄之,佚而劳之,亲而离之,攻其无备,出其不意。此兵家之胜,不可先传也。
夫未战而庙算胜者,得算多也;未战而庙算不胜者,得算少也。多算胜,少算不胜,而况无算乎!吾以此观之,胜负见矣。
作战第二
孙子曰:凡用兵之法,驰车千駟,革车千乘,带甲十万,千里馈粮。则内外之费,宾客之用,胶漆之材,车甲之奉,日费千金,然后十万之师举矣。
其用战也,贵胜,久则钝兵挫锐,攻城则力屈,久暴师则国用不足。夫钝兵挫锐,屈力殫货,则诸侯乘其弊而起,虽有智者,不能善其后矣。故兵闻拙速,未睹巧之久也。夫兵久而国利者,未之有也。故不尽知用兵之害者,则不能尽知用兵之利也。
善用兵者,役不再籍,粮不三载,取用於国,因粮於敌,故军食可足也。国之贫於师者远输,远输则百姓贫;近於师者贵卖,贵卖则百姓竭,财竭则急於丘役。力屈财殫,中原内虚於家,百姓之费,十去其七;公家之费,破军罢马,甲胄矢弩,戟楯矛櫓,丘牛大车,十去其六。
故智将务食於敌,食敌一钟,当吾二十钟;萁秆一石,当吾二十石。故杀敌者,怒也;取敌之利者,货也。故车战,得车十乘以上,赏其先得者,而更其旌旗。车杂而乘之,卒善而养之,是谓胜敌而益强。
故兵贵胜,不贵久。故知兵之将,民之司命。国家安危之主也。
谋攻第三
孙子曰:凡用兵之法,全国為上,破国次之;全军為上,破军次之;全旅為上,破旅次之;全卒為上,破卒次之;全伍為上,破伍次之。是故百战百胜,非善之善者也;不战而屈人之兵,善之善者也。
故上兵伐谋,其次伐交,其次伐兵,其下攻城。攻城之法,為不得已。修櫓轒轀,具器械,三月而后成;距闉,又三月而后已。将不胜其忿,而蚁附之,杀士三分之一,而城不拔者,此攻之灾也。
故善用兵者,屈人之兵,而非战也,拔人之城而非攻也,毁人之国而非久也,必以全争於天下,故兵不顿而利可全,此谋攻之法也。
故用兵之法,十则围之,五则攻之,倍则分之,敌则能战之,少则能逃之,不若则能避之。故小敌之坚,大敌之擒也。
夫将者,国之辅也。辅周则国必强,辅隙则国必弱。故君之所以患於军者三:不知军之不可以进而谓之进,不知军之不可以退而谓之退,是谓縻军;不知三军之事,而同三军之政,则军士惑矣;不知三军之权,而同三军之任,则军士疑矣。三军既惑且疑,则诸侯之难至矣。是谓乱军引胜。
故知胜有五:知可以战与不可以战者,胜。识眾寡之用者,胜。上下同欲者,胜。以虞待不虞者,胜。将能而君不御者,胜。此五者,知胜之道也。
故曰:知己知彼,百战不貽;不知彼而知己,一胜一负;不知彼不知己,每战必败。
军形第四
孙子曰:昔之善战者,先為不可胜,以待敌之可胜。不可胜在己,可胜在敌。故善战者,能為不可胜,不能使敌必可胜。故曰:胜可知,而不可為。
不可胜者,守也;可胜者,攻也。守则不足,攻则有餘。善守者,藏於九地之下,善攻者,动於九天之上,故能自保而全胜也。
见胜不过眾人之所知,非善之善者也;战胜而天下曰善,非善之善者也。故举秋毫不為多力,见日月不為明目,闻雷霆不為聪耳。古之善战者,胜於易胜者也。故善战者之胜也,无智名,无勇功,故其战胜不忒。不忒者,其所措必胜,胜已败者也。故善战者,先立於不败之地,而不失敌之败也。是故胜兵先胜,而后求战,败兵先战而后求胜。善用兵者,修道而保法,故能為胜败之政。
兵法:一曰度,二曰量,三曰数,四曰称,五曰胜。地生度,度生量,量生数,数生称,称生胜。故胜兵若以鎰称銖,败兵若以銖称鎰。胜者之战,若决积水於千仞之谿者,形也。
兵势第五
孙子曰:凡治眾如治寡,分数是也;斗眾如斗寡,形名是也;三军之眾,可使必受敌而无败者,奇正是也;兵之所加,如以碫投卵者,虚实是也。
凡战者,以正合,以奇胜。故善出奇者,无穷如天地,不竭如江海。终而复始,日月是也。死而復生,四时是也。声不过五,五声之变,不可胜听也;色不过五,五色之变,不可胜观也;味不过五,五味之变,不可胜尝也;战势,不过奇正,奇正之变,不可胜穷也。奇正相生,如循环之无端,熟能穷之哉?
激水之疾,至於漂石者,势也;鷙鸟之疾,至於毁折者,节也。是故善战者,其势险,其节短。势如张弩,节如发机。
纷纷紜紜,斗乱而不可乱也;浑浑沌沌,形圆而不可败也。乱生於治,怯生於勇,弱生於强。治乱,数也;勇怯,势也;强弱,形也。故善动敌者,形之,敌必从之;予之,敌必取之。以利动之,以卒待之。
故善战者,求之於势,不责於人;故能择人而任势。任势者,其战人也,如转木石。木石之性,安则静,危则动,方则止,圆则行。故善战人之势,如转圆石於千仞之山者,势也。
虚实第六
孙子曰:凡先处战地而待敌者佚,后处战地而趋战者劳。
故善战者,致人而不致於人。能使敌人自至者,利之也;能使敌人不得至者,害之也。故敌佚能劳之,饱能饥之,安能动之。出其所必趋,趋其所不意。行千里而不劳者,行於无人之地也;攻而必取者,攻其所不守也。守而必固者,守其所不攻也。
故善攻者,敌不知其所守;善守者,敌不知其所攻。微乎微乎,至於无形;神乎神乎,至於无声,故能為敌之司命。进而不可御者,冲其虚也;退而不可追者,速而不可及也。故我欲战,敌虽高垒深沟,不得不与我战者,攻其所必救也;我不欲战,虽画地而守之,敌不得与我战者,乖其所之也。故形人而我无形,则我专而敌分。我专為一,敌分為十,是以十攻其一也。则我眾敌寡,能以眾击寡者,则吾之所与战者约矣。吾所与战之地不可知,不可知则敌所备者多,敌所备者多,则吾所与战者寡矣。故备前则后寡,备后则前寡,备左则右寡,备右则左寡,无所不备,则无所不寡。寡者,备人者也;眾者,使人备己者也。故知战之地,知战之日,则可千里而会战;不知战之地,不知战日,则左不能救右,右不能救左,前不能救后,后不能救前,而况远者数十里,近者数里乎!以吾度之,越人之兵虽多,亦奚益於胜哉!故曰:胜可為也。敌虽眾,可使无斗。故策之而知得失之计,候之而知动静之理,形之而知死生之地,角之而知有餘不足之处。故形兵之极,至於无形。无形则深间不能窥,智者不能谋。因形而措胜於眾,眾不能知。人皆知我所以胜之形,而莫知吾所以制胜之形。故其战胜不復,而应形於无穷。夫兵形象水,水之行避高而趋下,兵之形避实而击虚;水因地而制流,兵因敌而制胜。故兵无常势,水无常形。能因敌变化而取胜者,谓之神。故五行无常胜,四时无常位,日有短长,月有死生。
军争第七
孙子曰: 凡用兵之法,将受命於君,合军聚眾,交和而舍,莫难於军争。军争之难者,以迂為直,以患為利。故迂其途,而诱之以利,后人发,先人至,此知迂直之计者也。军争為利,军争為危。举军而争利则不及,委军而争利则輜重捐。是故捲甲而趋,日夜不处,倍道兼行,百裡而争利,则擒三将军,劲者先,疲者后,其法十一而至;五十里而争利,则蹶上将军,其法半至;三十里而争利,则三分之二至。是故军无輜重则亡,无粮食则亡,无委积则亡。故不知诸侯之谋者,不能豫交;不知山林、险阻、沮泽之形者,不能行军;不用乡导者,不能得地利。故兵以诈立,以利动,以分和為变者也。故其疾如风,其徐如林,侵掠如火,不动如山,难知如阴,动如雷震。掠乡分眾,廓地分利,悬权而动。先知迂直之计者胜,此军争之法也。《军政》曰:“言不相闻,故為之金鼓;视不相见,故為之旌旗。”夫金鼓旌旗者,所以一民之耳目也。民既专一,则勇者不得独进,怯者不得独退,此用眾之法也。故夜战多金鼓,昼战多旌旗,所以变人之耳目也。三军可夺气,将军可夺心。是故朝气锐,昼气惰,暮气归。善用兵者,避其锐气,击其惰归,此治气者也。以治待乱,以静待哗,此治心者也。以近待远,以佚待劳,以饱待饥,此治力者也。无邀正正之旗,无击堂堂之陈,此治变者也。故用兵之法,高陵勿向,背丘勿逆,佯北勿从,锐卒勿攻,饵兵勿食,归师勿遏,围师遗闕,穷寇勿迫,此用兵之法也。
九变第八
孙子曰: 凡用兵之法,将受命於君,合军聚合。泛地无舍,衢地合交,绝地无留,围地则谋,死地则战,途有所不由,军有所不击,城有所不攻,地有所不争,君命有所不受。故将通於九变之利者,知用兵矣;将不通九变之利,虽知地形,不能得地之利矣;治兵不知九变之术,虽知五利,不能得人之用矣。是故智者之虑,必杂於利害,杂於利而务可信也,杂於害而患可解也。是故屈诸侯者以害,役诸侯者以业,趋诸侯者以利。故用兵之法,无恃其不来,恃吾有以待之;无恃其不攻,恃吾有所不可攻也。故将有五危,必死可杀,必生可虏,忿速可侮,廉洁可辱,爱民可烦。凡此五者,将之过也,用兵之灾也。覆军杀将,必以五危,不可不察也。
行军第九
孙子曰:凡处军相敌,绝山依穀,视生处高,战隆无登,此处山之军也。绝水必远水,客绝水而来,勿迎之於水内,令半渡而击之利,欲战者,无附於水而迎客,视生处高,无迎水流,此处水上之军也。绝斥泽,唯亟去无留,若交军於斥泽之中,必依水草而背眾树,此处斥泽之军也。平陆处易,右背高,前死后生,此处平陆之军也。凡此四军之利,黄帝之所以胜四帝也。凡军好高而恶下,贵阳而贱阴,养生而处实,军无百疾,是谓必胜。丘陵堤防,必处其阳而右背之,此兵之利,地之助也。上雨水流至,欲涉者,待其定也。凡地有绝涧、天井、天牢、天罗、天陷、天隙,必亟去之,勿近也。吾远之,敌近之;吾迎之,敌背之。军旁有险阻、潢井、蒹葭、小林、蘙薈者,必谨覆索之,此伏姦之所处也。敌近而静者,恃其险也;远而挑战者,欲人之进也;其所居易者,利也;眾树动者,来也;眾草多障者,疑也;鸟起者,伏也;兽骇者,覆也;尘高而锐者,车来也;卑而广者,徒来也;散而条达者,樵採也;少而往来者,营军也;辞卑而备者,进也;辞强而进驱者,退也;轻车先出居其侧者,陈也;无约而请和者,谋也;奔走而陈兵者,期也;半进半退者,诱也;杖而立者,饥也;汲而先饮者,渴也;见利而不进者,劳也;鸟集者,虚也;夜呼者,恐也;军扰者,将不重也;旌旗动者,乱也;吏怒者,倦也;杀马肉食者,军无粮也;悬甀不返其舍者,穷寇也;谆谆翕翕,徐与人言者,失眾也;数赏者,窘也;数罚者,困也;先暴而后畏其眾者,不精之至也;来委谢者,欲休息也。兵怒而相迎,久而不合,又不相去,必谨察之。兵非贵益多也,惟无武进,足以并力料敌取人而已。夫惟无虑而易敌者,必擒於人。卒未亲而罚之,则不服,不服则难用。卒已亲附而罚不行,则不可用。故合之以文,齐之以武,是谓必取。令素行以教其民,则民服;令素不行以教其民,则民不服。令素行者,与眾相得也。
地形第十
孙子曰:地形有通者、有掛者、有支者、有隘者、有险者、有远者。我可以往,彼可以来,曰通。通形者,先居高阳,利粮道,以战则利。可以往,难以返,曰掛。掛形者,敌无备,出而胜之,敌若有备,出而不胜,难以返,不利。我出而不利,彼出而不利,曰支。支形者,敌虽利我,我无出也,引而去之,令敌半出而击之利。隘形者,我先居之,必盈之以待敌。若敌先居之,盈而勿从,不盈而从之。险形者,我先居之,必居高阳以待敌;若敌先居之,引而去之,勿从也。远形者,势均难以挑战,战而不利。凡此六者,地之道也,将之至任,不可不察也。凡兵有走者、有驰者、有陷者、有崩者、有乱者、有北者。凡此六者,非天地之灾,将之过也。夫势均,以一击十,曰走;卒强吏弱,曰驰;吏强卒弱,曰陷;大吏怒而不服,遇敌懟而自战,将不知其能,曰崩;将弱不严,教道不明,吏卒无常,陈兵纵横,曰乱;将不能料敌,以少合眾,以弱击强,兵无选锋,曰北。凡此六者,败之道也,将之至任,不可不察也。夫地形者,兵之助也。料敌制胜,计险隘远近,上将之道也。知此而用战者必胜,不知此而用战者必败。故战道必胜,主曰无战,必战可也;战道不胜,主曰必战,无战可也。故进不求名,退不避罪,唯民是保,而利於主,国之宝也。视卒如婴儿,故可以与之赴深溪;视卒如爱子,故可与之俱死。厚而不能使,爱而不能令,乱而不能治,譬若骄子,不可用也。知吾卒之可以击,而不知敌之不可击,胜之半也;知敌之可击,而不知吾卒之不可以击,胜之半也;知敌之可击,知吾卒之可以击,而不知地形之不可以战,胜之半也。故知兵者,动而不迷,举而不穷。故曰:知彼知己,胜乃不殆;知天知地,胜乃可全。
九地第十一
孙子曰:用兵之法,有散地,有轻地,有争地,有交地,有衢地,有重地,有泛地,有围地,有死地。诸侯自战其地者,為散地;入人之地不深者,為轻地;我得亦利,彼得亦利者,為争地;我可以往,彼可以来者,為交地;诸侯之地三属,先至而得天下眾者,為衢地;入人之地深,背城邑多者,為重地;山林、险阻、沮泽,凡难行之道者,為泛地;所由入者隘,所从归者迂,彼寡可以击吾之眾者,為围地;疾战则存,不疾战则亡者,為死地。是故散地则无战,轻地则无止,争地则无攻,交地则无绝,衢地则合交,重地则掠,泛地则行,围地则谋,死地则战。古之善用兵者,能使敌人前后不相及,眾寡不相恃,贵贱不相救,上下不相收,卒离而不集,兵合而不齐。合於利而动,不合於利而止。敢问敌眾而整将来,待之若何曰:先夺其所爱则听矣。兵之情主速,乘人之不及。由不虞之道,攻其所不戒也。凡為客之道,深入则专。主人不克,掠於饶野,三军足食。谨养而勿劳,并气积力,运兵计谋,為不可测。投之无所往,死且不北。死焉不得,士人尽力。兵士甚陷则不惧,无所往则固,深入则拘,不得已则斗。是故其兵不修而戒,不求而得,不约而亲,不令而信,禁祥去疑,至死无所之。吾士无餘财,非恶货也;无餘命,非恶寿也。令发之日,士卒坐者涕沾襟,偃卧者涕交颐,投之无所往,诸、劌之勇也。故善用兵者,譬如率然。率然者,常山之蛇也。击其首则尾至,击其尾则首至,击其中则首尾俱至。敢问兵可使如率然乎?曰可。夫吴人与越人相恶也,当其同舟而济而遇风,其相救也如左右手。是故方马埋轮,未足恃也;齐勇如一,政之道也;刚柔皆得,地之理也。故善用兵者,携手若使一人,不得已也。将军之事,静以幽,正以治,能愚士卒之耳目,使之无知;易其事,革其谋,使人无识;易其居,迂其途,使民不得虑。帅与之期,如登高而去其梯;帅与之深入诸侯之地,而发其机。若驱群羊,驱而往,驱而来,莫知所之。聚三军之眾,投之於险,此谓将军之事也。九地之变,屈伸之力,人情之理,不可不察也。凡為客之道,深则专,浅则散。去国越境而师者,绝地也;四彻者,衢地也;入深者,重地也;入浅者,轻地也;背固前隘者,围地也;无所往者,死地也。是故散地吾将一其志,轻地吾将使之属,争地吾将趋其后,交地吾将谨其守,交地吾将固其结,衢地吾将谨其恃,重地吾将继其食,泛地吾将进其途,围地吾将塞其闕,死地吾将示之以不活。故兵之情:围则御,不得已则斗,过则从。是故不知诸侯之谋者,不能预交;不知山林、险阻、沮泽之形者,不能行军;不用乡导,不能得地利。四五者,一不知,非霸王之兵也。夫霸王之兵,伐大国,则其眾不得聚;威加於敌,则其交不得合。是故不争天下之交,不养天下之权,信己之私,威加於敌,则其城可拔,其国可隳。施无法之赏,悬无政之令。犯三军之眾,若使一人。犯之以事,勿告以言;犯之以害,勿告以利。投之亡地然后存,陷之死地然后生。夫眾陷於害,然后能為胜败。故為兵之事,在顺详敌之意,并敌一向,千里杀将,是谓巧能成事。是故政举之日,夷关折符,无通其使,厉於廊庙之上,以诛其事。敌人开闔,必亟入之,先其所爱,微与之期,践墨随敌,以决战事。是故始如处女,敌人开户;后如脱兔,敌不及拒。
火攻第十二
孙子曰:凡火攻有五:一曰火人,二曰火积,三曰火輜,四曰火库,五曰火队。行火必有因,因必素具。发火有时,起火有日。时者,天之燥也。日者,月在箕、壁、翼、軫也。凡此四宿者,风起之日也。凡火攻,必因五火之变而应之:火发於内,则早应之於外;火发而其兵静者,待而勿攻,极其火力,可从而从之,不可从则上。火可发於外,无待於内,以时发之,火发上风,无攻下风,昼风久,夜风止。凡军必知五火之变,以数守之。故以火佐攻者明,以水佐攻者强。水可以绝,不可以夺。夫战胜攻取而不惰其功者凶,命曰“费留”。故曰:明主虑之,良将惰之,非利不动,非得不用,非危不战。主不可以怒而兴师,将不可以慍而攻战。合於利而动,不合於利而上。怒可以复喜,慍可以复说,亡国不可以复存,死者不可以复生。故明主慎之,良将警之。此安国全军之道也。
用间第十三
孙子曰: 凡兴师十万,出征千里,百姓之费,公家之奉,日费千金,内外骚动,怠於道路,不得操事者,七十万家。相守数年,以争一日之胜,而爱爵禄百金,不知敌之情者,不仁之至也,非民之将也,非主之佐也,非胜之主也。故明君贤将所以动而胜人,成功出於眾者,先知也。先知者,不可取於鬼神,不可象於事,不可验於度,必取於人,知敌之情者也。故用间有五:有因间,有内间,有反间,有死间,有生间。五间俱起,莫知其道,是谓神纪,人君之宝也。乡间者,因其乡人而用之;内间者,因其官人而用之;反间者,因其敌间而用之;死间者,為誑事於外,令吾闻知之而传於敌间也;生间者,反报也。故三军之事,莫亲於间,赏莫厚於间,事莫密於间,非圣贤不能用间,非仁义不能使间,非微妙不能得间之实。微哉微哉!无所不用间也。间事未发而先闻者,间与所告者兼死。凡军之所欲击,城之所欲攻,人之所欲杀,必先知其守将、左右、謁者、门者、舍人之姓名,令吾间必索知之。敌间之来间我者,因而利之,导而舍之,故反间可得而用也;因是而知之,故乡间、内间可得而使也;因是而知之,故死间為誑事,可使告敌;因是而知之,故生间可使如期。五间之事,主必知之,知之必在於反间,故反间不可不厚也。昔殷之兴也,伊挚在夏;周之兴也,吕牙在殷。故明君贤将,能以上智為间者,必成大功。此兵之要,三军之所恃而动也。

View File

@ -0,0 +1,106 @@
This file was derived from
http://www.gutenberg.org/files/23864/23864-0.txt
--------
始計第一
孫子曰:兵者,國之大事,死生之地,存亡之道,不可不察也。
故經之以五事,校之以計,而索其情:一曰道,二曰天,三曰地,四曰將,五曰法。
道者,令民與上同意,可與之死,可與之生,而不畏危也;天者,陰陽、寒暑、時制也;地者,遠近、險易、廣狹、死生也;將者,智、信、仁、勇、嚴也;法者,曲制、官道、主用也。凡此五者,將莫不聞,知之者勝,不知者不勝。
故校之以計,而索其情,曰:主孰有道?將孰有能?天地孰得?法令孰行?兵眾孰強?士卒孰練?賞罰孰明?吾以此知勝負矣。
將聽吾計,用之必勝,留之;將不聽吾計,用之必敗,去之。
計利以聽,乃為之勢,以佐其外。勢者,因利而制權也。
兵者,詭道也。故能而示之不能,用而示之不用,近而示之遠,遠而示之近。利而誘之,亂而取之,實而備之,強而避之,怒而撓之,卑而驕之,佚而勞之,親而離之,攻其無備,出其不意。此兵家之勝,不可先傳也。
夫未戰而廟算勝者,得算多也;未戰而廟算不勝者,得算少也。多算勝,少算不勝,而況無算乎!吾以此觀之,勝負見矣。
作戰第二
孫子曰:凡用兵之法,馳車千駟,革車千乘,帶甲十萬,千里饋糧。則內外之費,賓客之用,膠漆之材,車甲之奉,日費千金,然後十萬之師舉矣。
其用戰也,貴勝,久則鈍兵挫銳,攻城則力屈,久暴師則國用不足。夫鈍兵挫銳,屈力殫貨,則諸侯乘其弊而起,雖有智者,不能善其後矣。故兵聞拙速,未睹巧之久也。夫兵久而國利者,未之有也。故不盡知用兵之害者,則不能盡知用兵之利也。
善用兵者,役不再籍,糧不三載,取用於國,因糧於敵,故軍食可足也。國之貧於師者遠輸,遠輸則百姓貧;近於師者貴賣,貴賣則百姓竭,財竭則急於丘役。力屈財殫,中原內虛於家,百姓之費,十去其七;公家之費,破軍罷馬,甲胄矢弩,戟楯矛櫓,丘牛大車,十去其六。
故智將務食於敵,食敵一鍾,當吾二十鍾;萁稈一石,當吾二十石。故殺敵者,怒也;取敵之利者,貨也。故車戰,得車十乘以上,賞其先得者,而更其旌旗。車雜而乘之,卒善而養之,是謂勝敵而益強。
故兵貴勝,不貴久。故知兵之將,民之司命。國家安危之主也。
謀攻第三
孫子曰:凡用兵之法,全國為上,破國次之;全軍為上,破軍次之;全旅為上,破旅次之;全卒為上,破卒次之;全伍為上,破伍次之。是故百戰百勝,非善之善者也;不戰而屈人之兵,善之善者也。
故上兵伐謀,其次伐交,其次伐兵,其下攻城。攻城之法,為不得已。修櫓轒轀,具器械,三月而後成;距闉,又三月而後已。將不勝其忿,而蟻附之,殺士三分之一,而城不拔者,此攻之災也。
故善用兵者,屈人之兵,而非戰也,拔人之城而非攻也,毀人之國而非久也,必以全爭於天下,故兵不頓而利可全,此謀攻之法也。
故用兵之法,十則圍之,五則攻之,倍則分之,敵則能戰之,少則能逃之,不若則能避之。故小敵之堅,大敵之擒也。
夫將者,國之輔也。輔周則國必強,輔隙則國必弱。故君之所以患於軍者三:不知軍之不可以進而謂之進,不知軍之不可以退而謂之退,是謂縻軍;不知三軍之事,而同三軍之政,則軍士惑矣;不知三軍之權,而同三軍之任,則軍士疑矣。三軍既惑且疑,則諸侯之難至矣。是謂亂軍引勝。
故知勝有五:知可以戰與不可以戰者,勝。識眾寡之用者,勝。上下同欲者,勝。以虞待不虞者,勝。將能而君不御者,勝。此五者,知勝之道也。
故曰:知己知彼,百戰不貽;不知彼而知己,一勝一負;不知彼不知己,每戰必敗。
軍形第四
孫子曰:昔之善戰者,先為不可勝,以待敵之可勝。不可勝在己,可勝在敵。故善戰者,能為不可勝,不能使敵必可勝。故曰:勝可知,而不可為。
不可勝者,守也;可勝者,攻也。守則不足,攻則有餘。善守者,藏於九地之下,善攻者,動於九天之上,故能自保而全勝也。
見勝不過眾人之所知,非善之善者也;戰勝而天下曰善,非善之善者也。故舉秋毫不為多力,見日月不為明目,聞雷霆不為聰耳。古之善戰者,勝於易勝者也。故善戰者之勝也,無智名,無勇功,故其戰勝不忒。不忒者,其所措必勝,勝已敗者也。故善戰者,先立於不敗之地,而不失敵之敗也。是故勝兵先勝,而後求戰,敗兵先戰而後求勝。善用兵者,修道而保法,故能為勝敗之政。
兵法:一曰度,二曰量,三曰數,四曰稱,五曰勝。地生度,度生量,量生數,數生稱,稱生勝。故勝兵若以鎰稱銖,敗兵若以銖稱鎰。勝者之戰,若決積水於千仞之谿者,形也。
兵勢第五
孫子曰:凡治眾如治寡,分數是也;鬥眾如鬥寡,形名是也;三軍之眾,可使必受敵而無敗者,奇正是也;兵之所加,如以碫投卵者,虛實是也。
凡戰者,以正合,以奇勝。故善出奇者,無窮如天地,不竭如江海。終而複始,日月是也。死而復生,四時是也。聲不過五,五聲之變,不可勝聽也;色不過五,五色之變,不可勝觀也;味不過五,五味之變,不可勝嘗也;戰勢,不過奇正,奇正之變,不可勝窮也。奇正相生,如循環之無端,熟能窮之哉?
激水之疾,至於漂石者,勢也;鷙鳥之疾,至於毀折者,節也。是故善戰者,其勢險,其節短。勢如張弩,節如發機。
紛紛紜紜,鬥亂而不可亂也;渾渾沌沌,形圓而不可敗也。亂生於治,怯生於勇,弱生於強。治亂,數也;勇怯,勢也;強弱,形也。故善動敵者,形之,敵必從之;予之,敵必取之。以利動之,以卒待之。
故善戰者,求之於勢,不責於人;故能擇人而任勢。任勢者,其戰人也,如轉木石。木石之性,安則靜,危則動,方則止,圓則行。故善戰人之勢,如轉圓石於千仞之山者,勢也。
虛實第六
孫子曰:凡先處戰地而待敵者佚,後處戰地而趨戰者勞。
故善戰者,致人而不致於人。能使敵人自至者,利之也;能使敵人不得至者,害之也。故敵佚能勞之,飽能饑之,安能動之。出其所必趨,趨其所不意。行千里而不勞者,行於無人之地也;攻而必取者,攻其所不守也。守而必固者,守其所不攻也。
故善攻者,敵不知其所守;善守者,敵不知其所攻。微乎微乎,至於無形;神乎神乎,至於無聲,故能為敵之司命。進而不可禦者,沖其虛也;退而不可追者,速而不可及也。故我欲戰,敵雖高壘深溝,不得不與我戰者,攻其所必救也;我不欲戰,雖畫地而守之,敵不得與我戰者,乖其所之也。故形人而我無形,則我專而敵分。我專為一,敵分為十,是以十攻其一也。則我眾敵寡,能以眾擊寡者,則吾之所與戰者約矣。吾所與戰之地不可知,不可知則敵所備者多,敵所備者多,則吾所與戰者寡矣。故備前則後寡,備後則前寡,備左則右寡,備右則左寡,無所不備,則無所不寡。寡者,備人者也;眾者,使人備己者也。故知戰之地,知戰之日,則可千里而會戰;不知戰之地,不知戰日,則左不能救右,右不能救左,前不能救後,後不能救前,而況遠者數十裏,近者數裏乎!以吾度之,越人之兵雖多,亦奚益於勝哉!故曰:勝可為也。敵雖眾,可使無鬥。故策之而知得失之計,候之而知動靜之理,形之而知死生之地,角之而知有餘不足之處。故形兵之極,至於無形。無形則深間不能窺,智者不能謀。因形而措勝於眾,眾不能知。人皆知我所以勝之形,而莫知吾所以制勝之形。故其戰勝不復,而應形於無窮。夫兵形象水,水之行避高而趨下,兵之形避實而擊虛;水因地而制流,兵因敵而制勝。故兵無常勢,水無常形。能因敵變化而取勝者,謂之神。故五行無常勝,四時無常位,日有短長,月有死生。
軍爭第七
孫子曰: 凡用兵之法,將受命於君,合軍聚眾,交和而舍,莫難於軍爭。軍爭之難者,以迂為直,以患為利。故迂其途,而誘之以利,後人發,先人至,此知迂直之計者也。軍爭為利,軍爭為危。舉軍而爭利則不及,委軍而爭利則輜重捐。是故捲甲而趨,日夜不處,倍道兼行,百裡而爭利,則擒三將軍,勁者先,疲者後,其法十一而至;五十裏而爭利,則蹶上將軍,其法半至;三十裏而爭利,則三分之二至。是故軍無輜重則亡,無糧食則亡,無委積則亡。故不知諸侯之謀者,不能豫交;不知山林、險阻、沮澤之形者,不能行軍;不用鄉導者,不能得地利。故兵以詐立,以利動,以分和為變者也。故其疾如風,其徐如林,侵掠如火,不動如山,難知如陰,動如雷震。掠鄉分眾,廓地分利,懸權而動。先知迂直之計者勝,此軍爭之法也。《軍政》曰:“言不相聞,故為之金鼓;視不相見,故為之旌旗。”夫金鼓旌旗者,所以一民之耳目也。民既專一,則勇者不得獨進,怯者不得獨退,此用眾之法也。故夜戰多金鼓,晝戰多旌旗,所以變人之耳目也。三軍可奪氣,將軍可奪心。是故朝氣銳,晝氣惰,暮氣歸。善用兵者,避其銳氣,擊其惰歸,此治氣者也。以治待亂,以靜待嘩,此治心者也。以近待遠,以佚待勞,以飽待饑,此治力者也。無邀正正之旗,無擊堂堂之陳,此治變者也。故用兵之法,高陵勿向,背丘勿逆,佯北勿從,銳卒勿攻,餌兵勿食,歸師勿遏,圍師遺闕,窮寇勿迫,此用兵之法也。
九變第八
孫子曰: 凡用兵之法,將受命於君,合軍聚合。泛地無舍,衢地合交,絕地無留,圍地則謀,死地則戰,途有所不由,軍有所不擊,城有所不攻,地有所不爭,君命有所不受。故將通於九變之利者,知用兵矣;將不通九變之利,雖知地形,不能得地之利矣;治兵不知九變之術,雖知五利,不能得人之用矣。是故智者之慮,必雜於利害,雜於利而務可信也,雜於害而患可解也。是故屈諸侯者以害,役諸侯者以業,趨諸侯者以利。故用兵之法,無恃其不來,恃吾有以待之;無恃其不攻,恃吾有所不可攻也。故將有五危,必死可殺,必生可虜,忿速可侮,廉潔可辱,愛民可煩。凡此五者,將之過也,用兵之災也。覆軍殺將,必以五危,不可不察也。
行軍第九
孫子曰:凡處軍相敵,絕山依穀,視生處高,戰隆無登,此處山之軍也。絕水必遠水,客絕水而來,勿迎之於水內,令半渡而擊之利,欲戰者,無附於水而迎客,視生處高,無迎水流,此處水上之軍也。絕斥澤,唯亟去無留,若交軍於斥澤之中,必依水草而背眾樹,此處斥澤之軍也。平陸處易,右背高,前死後生,此處平陸之軍也。凡此四軍之利,黃帝之所以勝四帝也。凡軍好高而惡下,貴陽而賤陰,養生而處實,軍無百疾,是謂必勝。丘陵堤防,必處其陽而右背之,此兵之利,地之助也。上雨水流至,欲涉者,待其定也。凡地有絕澗、天井、天牢、天羅、天陷、天隙,必亟去之,勿近也。吾遠之,敵近之;吾迎之,敵背之。軍旁有險阻、潢井、蒹葭、小林、蘙薈者,必謹覆索之,此伏姦之所處也。敵近而靜者,恃其險也;遠而挑戰者,欲人之進也;其所居易者,利也;眾樹動者,來也;眾草多障者,疑也;鳥起者,伏也;獸駭者,覆也;塵高而銳者,車來也;卑而廣者,徒來也;散而條達者,樵採也;少而往來者,營軍也;辭卑而備者,進也;辭強而進驅者,退也;輕車先出居其側者,陳也;無約而請和者,謀也;奔走而陳兵者,期也;半進半退者,誘也;杖而立者,饑也;汲而先飲者,渴也;見利而不進者,勞也;鳥集者,虛也;夜呼者,恐也;軍擾者,將不重也;旌旗動者,亂也;吏怒者,倦也;殺馬肉食者,軍無糧也;懸甀不返其舍者,窮寇也;諄諄翕翕,徐與人言者,失眾也;數賞者,窘也;數罰者,困也;先暴而後畏其眾者,不精之至也;來委謝者,欲休息也。兵怒而相迎,久而不合,又不相去,必謹察之。兵非貴益多也,惟無武進,足以並力料敵取人而已。夫惟無慮而易敵者,必擒於人。卒未親而罰之,則不服,不服則難用。卒已親附而罰不行,則不可用。故合之以文,齊之以武,是謂必取。令素行以教其民,則民服;令素不行以教其民,則民不服。令素行者,與眾相得也。
地形第十
孫子曰:地形有通者、有掛者、有支者、有隘者、有險者、有遠者。我可以往,彼可以來,曰通。通形者,先居高陽,利糧道,以戰則利。可以往,難以返,曰掛。掛形者,敵無備,出而勝之,敵若有備,出而不勝,難以返,不利。我出而不利,彼出而不利,曰支。支形者,敵雖利我,我無出也,引而去之,令敵半出而擊之利。隘形者,我先居之,必盈之以待敵。若敵先居之,盈而勿從,不盈而從之。險形者,我先居之,必居高陽以待敵;若敵先居之,引而去之,勿從也。遠形者,勢均難以挑戰,戰而不利。凡此六者,地之道也,將之至任,不可不察也。凡兵有走者、有馳者、有陷者、有崩者、有亂者、有北者。凡此六者,非天地之災,將之過也。夫勢均,以一擊十,曰走;卒強吏弱,曰馳;吏強卒弱,曰陷;大吏怒而不服,遇敵懟而自戰,將不知其能,曰崩;將弱不嚴,教道不明,吏卒無常,陳兵縱橫,曰亂;將不能料敵,以少合眾,以弱擊強,兵無選鋒,曰北。凡此六者,敗之道也,將之至任,不可不察也。夫地形者,兵之助也。料敵制勝,計險隘遠近,上將之道也。知此而用戰者必勝,不知此而用戰者必敗。故戰道必勝,主曰無戰,必戰可也;戰道不勝,主曰必戰,無戰可也。故進不求名,退不避罪,唯民是保,而利於主,國之寶也。視卒如嬰兒,故可以與之赴深溪;視卒如愛子,故可與之俱死。厚而不能使,愛而不能令,亂而不能治,譬若驕子,不可用也。知吾卒之可以擊,而不知敵之不可擊,勝之半也;知敵之可擊,而不知吾卒之不可以擊,勝之半也;知敵之可擊,知吾卒之可以擊,而不知地形之不可以戰,勝之半也。故知兵者,動而不迷,舉而不窮。故曰:知彼知己,勝乃不殆;知天知地,勝乃可全。
九地第十一
孫子曰:用兵之法,有散地,有輕地,有爭地,有交地,有衢地,有重地,有泛地,有圍地,有死地。諸侯自戰其地者,為散地;入人之地不深者,為輕地;我得亦利,彼得亦利者,為爭地;我可以往,彼可以來者,為交地;諸侯之地三屬,先至而得天下眾者,為衢地;入人之地深,背城邑多者,為重地;山林、險阻、沮澤,凡難行之道者,為泛地;所由入者隘,所從歸者迂,彼寡可以擊吾之眾者,為圍地;疾戰則存,不疾戰則亡者,為死地。是故散地則無戰,輕地則無止,爭地則無攻,交地則無絕,衢地則合交,重地則掠,泛地則行,圍地則謀,死地則戰。古之善用兵者,能使敵人前後不相及,眾寡不相恃,貴賤不相救,上下不相收,卒離而不集,兵合而不齊。合於利而動,不合於利而止。敢問敵眾而整將來,待之若何曰:先奪其所愛則聽矣。兵之情主速,乘人之不及。由不虞之道,攻其所不戒也。凡為客之道,深入則專。主人不克,掠於饒野,三軍足食。謹養而勿勞,並氣積力,運兵計謀,為不可測。投之無所往,死且不北。死焉不得,士人盡力。兵士甚陷則不懼,無所往則固,深入則拘,不得已則鬥。是故其兵不修而戒,不求而得,不約而親,不令而信,禁祥去疑,至死無所之。吾士無餘財,非惡貨也;無餘命,非惡壽也。令發之日,士卒坐者涕沾襟,偃臥者涕交頤,投之無所往,諸、劌之勇也。故善用兵者,譬如率然。率然者,常山之蛇也。擊其首則尾至,擊其尾則首至,擊其中則首尾俱至。敢問兵可使如率然乎?曰可。夫吳人與越人相惡也,當其同舟而濟而遇風,其相救也如左右手。是故方馬埋輪,未足恃也;齊勇如一,政之道也;剛柔皆得,地之理也。故善用兵者,攜手若使一人,不得已也。將軍之事,靜以幽,正以治,能愚士卒之耳目,使之無知;易其事,革其謀,使人無識;易其居,迂其途,使民不得慮。帥與之期,如登高而去其梯;帥與之深入諸侯之地,而發其機。若驅群羊,驅而往,驅而來,莫知所之。聚三軍之眾,投之於險,此謂將軍之事也。九地之變,屈伸之力,人情之理,不可不察也。凡為客之道,深則專,淺則散。去國越境而師者,絕地也;四徹者,衢地也;入深者,重地也;入淺者,輕地也;背固前隘者,圍地也;無所往者,死地也。是故散地吾將一其志,輕地吾將使之屬,爭地吾將趨其後,交地吾將謹其守,交地吾將固其結,衢地吾將謹其恃,重地吾將繼其食,泛地吾將進其途,圍地吾將塞其闕,死地吾將示之以不活。故兵之情:圍則禦,不得已則鬥,過則從。是故不知諸侯之謀者,不能預交;不知山林、險阻、沮澤之形者,不能行軍;不用鄉導,不能得地利。四五者,一不知,非霸王之兵也。夫霸王之兵,伐大國,則其眾不得聚;威加於敵,則其交不得合。是故不爭天下之交,不養天下之權,信己之私,威加於敵,則其城可拔,其國可隳。施無法之賞,懸無政之令。犯三軍之眾,若使一人。犯之以事,勿告以言;犯之以害,勿告以利。投之亡地然後存,陷之死地然後生。夫眾陷於害,然後能為勝敗。故為兵之事,在順詳敵之意,並敵一向,千里殺將,是謂巧能成事。是故政舉之日,夷關折符,無通其使,厲於廊廟之上,以誅其事。敵人開闔,必亟入之,先其所愛,微與之期,踐墨隨敵,以決戰事。是故始如處女,敵人開戶;後如脫兔,敵不及拒。
火攻第十二
孫子曰:凡火攻有五:一曰火人,二曰火積,三曰火輜,四曰火庫,五曰火隊。行火必有因,因必素具。發火有時,起火有日。時者,天之燥也。日者,月在箕、壁、翼、軫也。凡此四宿者,風起之日也。凡火攻,必因五火之變而應之:火發於內,則早應之於外;火發而其兵靜者,待而勿攻,極其火力,可從而從之,不可從則上。火可發於外,無待於內,以時發之,火發上風,無攻下風,晝風久,夜風止。凡軍必知五火之變,以數守之。故以火佐攻者明,以水佐攻者強。水可以絕,不可以奪。夫戰勝攻取而不惰其功者凶,命曰“費留”。故曰:明主慮之,良將惰之,非利不動,非得不用,非危不戰。主不可以怒而興師,將不可以慍而攻戰。合於利而動,不合於利而上。怒可以複喜,慍可以複說,亡國不可以複存,死者不可以複生。故明主慎之,良將警之。此安國全軍之道也。
用間第十三
孫子曰: 凡興師十萬,出征千里,百姓之費,公家之奉,日費千金,內外騷動,怠於道路,不得操事者,七十萬家。相守數年,以爭一日之勝,而愛爵祿百金,不知敵之情者,不仁之至也,非民之將也,非主之佐也,非勝之主也。故明君賢將所以動而勝人,成功出於眾者,先知也。先知者,不可取於鬼神,不可象於事,不可驗於度,必取於人,知敵之情者也。故用間有五:有因間,有內間,有反間,有死間,有生間。五間俱起,莫知其道,是謂神紀,人君之寶也。鄉間者,因其鄉人而用之;內間者,因其官人而用之;反間者,因其敵間而用之;死間者,為誑事於外,令吾聞知之而傳於敵間也;生間者,反報也。故三軍之事,莫親於間,賞莫厚於間,事莫密於間,非聖賢不能用間,非仁義不能使間,非微妙不能得間之實。微哉微哉!無所不用間也。間事未發而先聞者,間與所告者兼死。凡軍之所欲擊,城之所欲攻,人之所欲殺,必先知其守將、左右、謁者、門者、舍人之姓名,令吾間必索知之。敵間之來間我者,因而利之,導而舍之,故反間可得而用也;因是而知之,故鄉間、內間可得而使也;因是而知之,故死間為誑事,可使告敵;因是而知之,故生間可使如期。五間之事,主必知之,知之必在於反間,故反間不可不厚也。昔殷之興也,伊摯在夏;周之興也,呂牙在殷。故明君賢將,能以上智為間者,必成大功。此兵之要,三軍之所恃而動也。

View File

@ -0,0 +1,106 @@
This file was derived from
http://www.gutenberg.org/files/23864/23864-0.txt
--------
始計第一
孫子曰:兵者,國之大事,死生之地,存亡之道,不可不察也。
故經之以五事,校之以計,而索其情:一曰道,二曰天,三曰地,四曰將,五曰法。
道者,令民與上同意,可與之死,可與之生,而不畏危也;天者,陰陽、寒暑、時制也;地者,遠近、險易、廣狹、死生也;將者,智、信、仁、勇、嚴也;法者,曲制、官道、主用也。凡此五者,將莫不聞,知之者勝,不知者不勝。
故校之以計,而索其情,曰:主孰有道?將孰有能?天地孰得?法令孰行?兵眾孰強?士卒孰練?賞罰孰明?吾以此知勝負矣。
將聽吾計,用之必勝,留之;將不聽吾計,用之必敗,去之。
計利以聽,乃為之勢,以佐其外。勢者,因利而制權也。
兵者,詭道也。故能而示之不能,用而示之不用,近而示之遠,遠而示之近。利而誘之,亂而取之,實而備之,強而避之,怒而撓之,卑而驕之,佚而勞之,親而離之,攻其無備,出其不意。此兵家之勝,不可先傳也。
夫未戰而廟算勝者,得算多也;未戰而廟算不勝者,得算少也。多算勝,少算不勝,而況無算乎!吾以此觀之,勝負見矣。
作戰第二
孫子曰:凡用兵之法,馳車千駟,革車千乘,帶甲十萬,千里饋糧。則內外之費,賓客之用,膠漆之材,車甲之奉,日費千金,然後十萬之師舉矣。
其用戰也,貴勝,久則鈍兵挫銳,攻城則力屈,久暴師則國用不足。夫鈍兵挫銳,屈力殫貨,則諸侯乘其弊而起,雖有智者,不能善其後矣。故兵聞拙速,未睹巧之久也。夫兵久而國利者,未之有也。故不盡知用兵之害者,則不能盡知用兵之利也。
善用兵者,役不再籍,糧不三載,取用於國,因糧於敵,故軍食可足也。國之貧於師者遠輸,遠輸則百姓貧;近於師者貴賣,貴賣則百姓竭,財竭則急於丘役。力屈財殫,中原內虛於家,百姓之費,十去其七;公家之費,破軍罷馬,甲胄矢弩,戟楯矛櫓,丘牛大車,十去其六。
故智將務食於敵,食敵一鍾,當吾二十鍾;萁稈一石,當吾二十石。故殺敵者,怒也;取敵之利者,貨也。故車戰,得車十乘以上,賞其先得者,而更其旌旗。車雜而乘之,卒善而養之,是謂勝敵而益強。
故兵貴勝,不貴久。故知兵之將,民之司命。國家安危之主也。
謀攻第三
孫子曰:凡用兵之法,全國為上,破國次之;全軍為上,破軍次之;全旅為上,破旅次之;全卒為上,破卒次之;全伍為上,破伍次之。是故百戰百勝,非善之善者也;不戰而屈人之兵,善之善者也。
故上兵伐謀,其次伐交,其次伐兵,其下攻城。攻城之法,為不得已。修櫓轒轀,具器械,三月而後成;距闉,又三月而後已。將不勝其忿,而蟻附之,殺士三分之一,而城不拔者,此攻之災也。
故善用兵者,屈人之兵,而非戰也,拔人之城而非攻也,毀人之國而非久也,必以全爭於天下,故兵不頓而利可全,此謀攻之法也。
故用兵之法,十則圍之,五則攻之,倍則分之,敵則能戰之,少則能逃之,不若則能避之。故小敵之堅,大敵之擒也。
夫將者,國之輔也。輔周則國必強,輔隙則國必弱。故君之所以患於軍者三:不知軍之不可以進而謂之進,不知軍之不可以退而謂之退,是謂縻軍;不知三軍之事,而同三軍之政,則軍士惑矣;不知三軍之權,而同三軍之任,則軍士疑矣。三軍既惑且疑,則諸侯之難至矣。是謂亂軍引勝。
故知勝有五:知可以戰與不可以戰者,勝。識眾寡之用者,勝。上下同欲者,勝。以虞待不虞者,勝。將能而君不御者,勝。此五者,知勝之道也。
故曰:知己知彼,百戰不貽;不知彼而知己,一勝一負;不知彼不知己,每戰必敗。
軍形第四
孫子曰:昔之善戰者,先為不可勝,以待敵之可勝。不可勝在己,可勝在敵。故善戰者,能為不可勝,不能使敵必可勝。故曰:勝可知,而不可為。
不可勝者,守也;可勝者,攻也。守則不足,攻則有餘。善守者,藏於九地之下,善攻者,動於九天之上,故能自保而全勝也。
見勝不過眾人之所知,非善之善者也;戰勝而天下曰善,非善之善者也。故舉秋毫不為多力,見日月不為明目,聞雷霆不為聰耳。古之善戰者,勝於易勝者也。故善戰者之勝也,無智名,無勇功,故其戰勝不忒。不忒者,其所措必勝,勝已敗者也。故善戰者,先立於不敗之地,而不失敵之敗也。是故勝兵先勝,而後求戰,敗兵先戰而後求勝。善用兵者,修道而保法,故能為勝敗之政。
兵法:一曰度,二曰量,三曰數,四曰稱,五曰勝。地生度,度生量,量生數,數生稱,稱生勝。故勝兵若以鎰稱銖,敗兵若以銖稱鎰。勝者之戰,若決積水於千仞之谿者,形也。
兵勢第五
孫子曰:凡治眾如治寡,分數是也;鬥眾如鬥寡,形名是也;三軍之眾,可使必受敵而無敗者,奇正是也;兵之所加,如以碫投卵者,虛實是也。
凡戰者,以正合,以奇勝。故善出奇者,無窮如天地,不竭如江海。終而複始,日月是也。死而復生,四時是也。聲不過五,五聲之變,不可勝聽也;色不過五,五色之變,不可勝觀也;味不過五,五味之變,不可勝嘗也;戰勢,不過奇正,奇正之變,不可勝窮也。奇正相生,如循環之無端,熟能窮之哉?
激水之疾,至於漂石者,勢也;鷙鳥之疾,至於毀折者,節也。是故善戰者,其勢險,其節短。勢如張弩,節如發機。
紛紛紜紜,鬥亂而不可亂也;渾渾沌沌,形圓而不可敗也。亂生於治,怯生於勇,弱生於強。治亂,數也;勇怯,勢也;強弱,形也。故善動敵者,形之,敵必從之;予之,敵必取之。以利動之,以卒待之。
故善戰者,求之於勢,不責於人;故能擇人而任勢。任勢者,其戰人也,如轉木石。木石之性,安則靜,危則動,方則止,圓則行。故善戰人之勢,如轉圓石於千仞之山者,勢也。
虛實第六
孫子曰:凡先處戰地而待敵者佚,後處戰地而趨戰者勞。
故善戰者,致人而不致於人。能使敵人自至者,利之也;能使敵人不得至者,害之也。故敵佚能勞之,飽能饑之,安能動之。出其所必趨,趨其所不意。行千里而不勞者,行於無人之地也;攻而必取者,攻其所不守也。守而必固者,守其所不攻也。
故善攻者,敵不知其所守;善守者,敵不知其所攻。微乎微乎,至於無形;神乎神乎,至於無聲,故能為敵之司命。進而不可禦者,沖其虛也;退而不可追者,速而不可及也。故我欲戰,敵雖高壘深溝,不得不與我戰者,攻其所必救也;我不欲戰,雖畫地而守之,敵不得與我戰者,乖其所之也。故形人而我無形,則我專而敵分。我專為一,敵分為十,是以十攻其一也。則我眾敵寡,能以眾擊寡者,則吾之所與戰者約矣。吾所與戰之地不可知,不可知則敵所備者多,敵所備者多,則吾所與戰者寡矣。故備前則後寡,備後則前寡,備左則右寡,備右則左寡,無所不備,則無所不寡。寡者,備人者也;眾者,使人備己者也。故知戰之地,知戰之日,則可千里而會戰;不知戰之地,不知戰日,則左不能救右,右不能救左,前不能救後,後不能救前,而況遠者數十裏,近者數裏乎!以吾度之,越人之兵雖多,亦奚益於勝哉!故曰:勝可為也。敵雖眾,可使無鬥。故策之而知得失之計,候之而知動靜之理,形之而知死生之地,角之而知有餘不足之處。故形兵之極,至於無形。無形則深間不能窺,智者不能謀。因形而措勝於眾,眾不能知。人皆知我所以勝之形,而莫知吾所以制勝之形。故其戰勝不復,而應形於無窮。夫兵形象水,水之行避高而趨下,兵之形避實而擊虛;水因地而制流,兵因敵而制勝。故兵無常勢,水無常形。能因敵變化而取勝者,謂之神。故五行無常勝,四時無常位,日有短長,月有死生。
軍爭第七
孫子曰: 凡用兵之法,將受命於君,合軍聚眾,交和而舍,莫難於軍爭。軍爭之難者,以迂為直,以患為利。故迂其途,而誘之以利,後人發,先人至,此知迂直之計者也。軍爭為利,軍爭為危。舉軍而爭利則不及,委軍而爭利則輜重捐。是故捲甲而趨,日夜不處,倍道兼行,百裡而爭利,則擒三將軍,勁者先,疲者後,其法十一而至;五十裏而爭利,則蹶上將軍,其法半至;三十裏而爭利,則三分之二至。是故軍無輜重則亡,無糧食則亡,無委積則亡。故不知諸侯之謀者,不能豫交;不知山林、險阻、沮澤之形者,不能行軍;不用鄉導者,不能得地利。故兵以詐立,以利動,以分和為變者也。故其疾如風,其徐如林,侵掠如火,不動如山,難知如陰,動如雷震。掠鄉分眾,廓地分利,懸權而動。先知迂直之計者勝,此軍爭之法也。《軍政》曰:“言不相聞,故為之金鼓;視不相見,故為之旌旗。”夫金鼓旌旗者,所以一民之耳目也。民既專一,則勇者不得獨進,怯者不得獨退,此用眾之法也。故夜戰多金鼓,晝戰多旌旗,所以變人之耳目也。三軍可奪氣,將軍可奪心。是故朝氣銳,晝氣惰,暮氣歸。善用兵者,避其銳氣,擊其惰歸,此治氣者也。以治待亂,以靜待嘩,此治心者也。以近待遠,以佚待勞,以飽待饑,此治力者也。無邀正正之旗,無擊堂堂之陳,此治變者也。故用兵之法,高陵勿向,背丘勿逆,佯北勿從,銳卒勿攻,餌兵勿食,歸師勿遏,圍師遺闕,窮寇勿迫,此用兵之法也。
九變第八
孫子曰: 凡用兵之法,將受命於君,合軍聚合。泛地無舍,衢地合交,絕地無留,圍地則謀,死地則戰,途有所不由,軍有所不擊,城有所不攻,地有所不爭,君命有所不受。故將通於九變之利者,知用兵矣;將不通九變之利,雖知地形,不能得地之利矣;治兵不知九變之術,雖知五利,不能得人之用矣。是故智者之慮,必雜於利害,雜於利而務可信也,雜於害而患可解也。是故屈諸侯者以害,役諸侯者以業,趨諸侯者以利。故用兵之法,無恃其不來,恃吾有以待之;無恃其不攻,恃吾有所不可攻也。故將有五危,必死可殺,必生可虜,忿速可侮,廉潔可辱,愛民可煩。凡此五者,將之過也,用兵之災也。覆軍殺將,必以五危,不可不察也。
行軍第九
孫子曰:凡處軍相敵,絕山依穀,視生處高,戰隆無登,此處山之軍也。絕水必遠水,客絕水而來,勿迎之於水內,令半渡而擊之利,欲戰者,無附於水而迎客,視生處高,無迎水流,此處水上之軍也。絕斥澤,唯亟去無留,若交軍於斥澤之中,必依水草而背眾樹,此處斥澤之軍也。平陸處易,右背高,前死後生,此處平陸之軍也。凡此四軍之利,黃帝之所以勝四帝也。凡軍好高而惡下,貴陽而賤陰,養生而處實,軍無百疾,是謂必勝。丘陵堤防,必處其陽而右背之,此兵之利,地之助也。上雨水流至,欲涉者,待其定也。凡地有絕澗、天井、天牢、天羅、天陷、天隙,必亟去之,勿近也。吾遠之,敵近之;吾迎之,敵背之。軍旁有險阻、潢井、蒹葭、小林、蘙薈者,必謹覆索之,此伏姦之所處也。敵近而靜者,恃其險也;遠而挑戰者,欲人之進也;其所居易者,利也;眾樹動者,來也;眾草多障者,疑也;鳥起者,伏也;獸駭者,覆也;塵高而銳者,車來也;卑而廣者,徒來也;散而條達者,樵採也;少而往來者,營軍也;辭卑而備者,進也;辭強而進驅者,退也;輕車先出居其側者,陳也;無約而請和者,謀也;奔走而陳兵者,期也;半進半退者,誘也;杖而立者,饑也;汲而先飲者,渴也;見利而不進者,勞也;鳥集者,虛也;夜呼者,恐也;軍擾者,將不重也;旌旗動者,亂也;吏怒者,倦也;殺馬肉食者,軍無糧也;懸甀不返其舍者,窮寇也;諄諄翕翕,徐與人言者,失眾也;數賞者,窘也;數罰者,困也;先暴而後畏其眾者,不精之至也;來委謝者,欲休息也。兵怒而相迎,久而不合,又不相去,必謹察之。兵非貴益多也,惟無武進,足以並力料敵取人而已。夫惟無慮而易敵者,必擒於人。卒未親而罰之,則不服,不服則難用。卒已親附而罰不行,則不可用。故合之以文,齊之以武,是謂必取。令素行以教其民,則民服;令素不行以教其民,則民不服。令素行者,與眾相得也。
地形第十
孫子曰:地形有通者、有掛者、有支者、有隘者、有險者、有遠者。我可以往,彼可以來,曰通。通形者,先居高陽,利糧道,以戰則利。可以往,難以返,曰掛。掛形者,敵無備,出而勝之,敵若有備,出而不勝,難以返,不利。我出而不利,彼出而不利,曰支。支形者,敵雖利我,我無出也,引而去之,令敵半出而擊之利。隘形者,我先居之,必盈之以待敵。若敵先居之,盈而勿從,不盈而從之。險形者,我先居之,必居高陽以待敵;若敵先居之,引而去之,勿從也。遠形者,勢均難以挑戰,戰而不利。凡此六者,地之道也,將之至任,不可不察也。凡兵有走者、有馳者、有陷者、有崩者、有亂者、有北者。凡此六者,非天地之災,將之過也。夫勢均,以一擊十,曰走;卒強吏弱,曰馳;吏強卒弱,曰陷;大吏怒而不服,遇敵懟而自戰,將不知其能,曰崩;將弱不嚴,教道不明,吏卒無常,陳兵縱橫,曰亂;將不能料敵,以少合眾,以弱擊強,兵無選鋒,曰北。凡此六者,敗之道也,將之至任,不可不察也。夫地形者,兵之助也。料敵制勝,計險隘遠近,上將之道也。知此而用戰者必勝,不知此而用戰者必敗。故戰道必勝,主曰無戰,必戰可也;戰道不勝,主曰必戰,無戰可也。故進不求名,退不避罪,唯民是保,而利於主,國之寶也。視卒如嬰兒,故可以與之赴深溪;視卒如愛子,故可與之俱死。厚而不能使,愛而不能令,亂而不能治,譬若驕子,不可用也。知吾卒之可以擊,而不知敵之不可擊,勝之半也;知敵之可擊,而不知吾卒之不可以擊,勝之半也;知敵之可擊,知吾卒之可以擊,而不知地形之不可以戰,勝之半也。故知兵者,動而不迷,舉而不窮。故曰:知彼知己,勝乃不殆;知天知地,勝乃可全。
九地第十一
孫子曰:用兵之法,有散地,有輕地,有爭地,有交地,有衢地,有重地,有泛地,有圍地,有死地。諸侯自戰其地者,為散地;入人之地不深者,為輕地;我得亦利,彼得亦利者,為爭地;我可以往,彼可以來者,為交地;諸侯之地三屬,先至而得天下眾者,為衢地;入人之地深,背城邑多者,為重地;山林、險阻、沮澤,凡難行之道者,為泛地;所由入者隘,所從歸者迂,彼寡可以擊吾之眾者,為圍地;疾戰則存,不疾戰則亡者,為死地。是故散地則無戰,輕地則無止,爭地則無攻,交地則無絕,衢地則合交,重地則掠,泛地則行,圍地則謀,死地則戰。古之善用兵者,能使敵人前後不相及,眾寡不相恃,貴賤不相救,上下不相收,卒離而不集,兵合而不齊。合於利而動,不合於利而止。敢問敵眾而整將來,待之若何曰:先奪其所愛則聽矣。兵之情主速,乘人之不及。由不虞之道,攻其所不戒也。凡為客之道,深入則專。主人不克,掠於饒野,三軍足食。謹養而勿勞,並氣積力,運兵計謀,為不可測。投之無所往,死且不北。死焉不得,士人盡力。兵士甚陷則不懼,無所往則固,深入則拘,不得已則鬥。是故其兵不修而戒,不求而得,不約而親,不令而信,禁祥去疑,至死無所之。吾士無餘財,非惡貨也;無餘命,非惡壽也。令發之日,士卒坐者涕沾襟,偃臥者涕交頤,投之無所往,諸、劌之勇也。故善用兵者,譬如率然。率然者,常山之蛇也。擊其首則尾至,擊其尾則首至,擊其中則首尾俱至。敢問兵可使如率然乎?曰可。夫吳人與越人相惡也,當其同舟而濟而遇風,其相救也如左右手。是故方馬埋輪,未足恃也;齊勇如一,政之道也;剛柔皆得,地之理也。故善用兵者,攜手若使一人,不得已也。將軍之事,靜以幽,正以治,能愚士卒之耳目,使之無知;易其事,革其謀,使人無識;易其居,迂其途,使民不得慮。帥與之期,如登高而去其梯;帥與之深入諸侯之地,而發其機。若驅群羊,驅而往,驅而來,莫知所之。聚三軍之眾,投之於險,此謂將軍之事也。九地之變,屈伸之力,人情之理,不可不察也。凡為客之道,深則專,淺則散。去國越境而師者,絕地也;四徹者,衢地也;入深者,重地也;入淺者,輕地也;背固前隘者,圍地也;無所往者,死地也。是故散地吾將一其志,輕地吾將使之屬,爭地吾將趨其後,交地吾將謹其守,交地吾將固其結,衢地吾將謹其恃,重地吾將繼其食,泛地吾將進其途,圍地吾將塞其闕,死地吾將示之以不活。故兵之情:圍則禦,不得已則鬥,過則從。是故不知諸侯之謀者,不能預交;不知山林、險阻、沮澤之形者,不能行軍;不用鄉導,不能得地利。四五者,一不知,非霸王之兵也。夫霸王之兵,伐大國,則其眾不得聚;威加於敵,則其交不得合。是故不爭天下之交,不養天下之權,信己之私,威加於敵,則其城可拔,其國可隳。施無法之賞,懸無政之令。犯三軍之眾,若使一人。犯之以事,勿告以言;犯之以害,勿告以利。投之亡地然後存,陷之死地然後生。夫眾陷於害,然後能為勝敗。故為兵之事,在順詳敵之意,並敵一向,千里殺將,是謂巧能成事。是故政舉之日,夷關折符,無通其使,厲於廊廟之上,以誅其事。敵人開闔,必亟入之,先其所愛,微與之期,踐墨隨敵,以決戰事。是故始如處女,敵人開戶;後如脫兔,敵不及拒。
火攻第十二
孫子曰:凡火攻有五:一曰火人,二曰火積,三曰火輜,四曰火庫,五曰火隊。行火必有因,因必素具。發火有時,起火有日。時者,天之燥也。日者,月在箕、壁、翼、軫也。凡此四宿者,風起之日也。凡火攻,必因五火之變而應之:火發於內,則早應之於外;火發而其兵靜者,待而勿攻,極其火力,可從而從之,不可從則上。火可發於外,無待於內,以時發之,火發上風,無攻下風,晝風久,夜風止。凡軍必知五火之變,以數守之。故以火佐攻者明,以水佐攻者強。水可以絕,不可以奪。夫戰勝攻取而不惰其功者凶,命曰“費留”。故曰:明主慮之,良將惰之,非利不動,非得不用,非危不戰。主不可以怒而興師,將不可以慍而攻戰。合於利而動,不合於利而上。怒可以複喜,慍可以複說,亡國不可以複存,死者不可以複生。故明主慎之,良將警之。此安國全軍之道也。
用間第十三
孫子曰: 凡興師十萬,出征千里,百姓之費,公家之奉,日費千金,內外騷動,怠於道路,不得操事者,七十萬家。相守數年,以爭一日之勝,而愛爵祿百金,不知敵之情者,不仁之至也,非民之將也,非主之佐也,非勝之主也。故明君賢將所以動而勝人,成功出於眾者,先知也。先知者,不可取於鬼神,不可象於事,不可驗於度,必取於人,知敵之情者也。故用間有五:有因間,有內間,有反間,有死間,有生間。五間俱起,莫知其道,是謂神紀,人君之寶也。鄉間者,因其鄉人而用之;內間者,因其官人而用之;反間者,因其敵間而用之;死間者,為誑事於外,令吾聞知之而傳於敵間也;生間者,反報也。故三軍之事,莫親於間,賞莫厚於間,事莫密於間,非聖賢不能用間,非仁義不能使間,非微妙不能得間之實。微哉微哉!無所不用間也。間事未發而先聞者,間與所告者兼死。凡軍之所欲擊,城之所欲攻,人之所欲殺,必先知其守將、左右、謁者、門者、舍人之姓名,令吾間必索知之。敵間之來間我者,因而利之,導而舍之,故反間可得而用也;因是而知之,故鄉間、內間可得而使也;因是而知之,故死間為誑事,可使告敵;因是而知之,故生間可使如期。五間之事,主必知之,知之必在於反間,故反間不可不厚也。昔殷之興也,伊摯在夏;周之興也,呂牙在殷。故明君賢將,能以上智為間者,必成大功。此兵之要,三軍之所恃而動也。

View File

@ -0,0 +1,175 @@
This file was derived from
http://www.ibrary.co.kr/index.php/book-list/short-stories/34-short-stories-korean/150-2008-04-20-13-22-32
--------
[소개]
잔인한 운명은 이렇게 인간을 조롱하곤 한다. 우리가 평소 마음 속 저 깊은 곳에 움켜쥐고 있던 자존심 따위는 어느 한 순간 전혀 무용지물이란 것이 드러나고 만다. 하기야 이렇게 삶의 한 순간, 눈 깜짝할 새에 우리를 후려 갈기고 지나가는 그 진실이 미래의 어느날에는 또 남김없이 우리 눈 앞에 펼쳐질지도 모른다. 죽음을 앞둔 사람들에게는 자신의 삶 전체가 한 순간에 다시 보인다는 그런 얘기도 있던데...
다시 읽어보니 끔찍한 생각도 든다. 식민지 시대의 암울한 삶, 그 끈끈한 냄새를 피할 수 없다. 21세기를 사는 우리들에겐 그런 냄새는 아예 인연이 없는 것처럼 느껴질 수도 있을 것이다. 그러나 과연 그럴까? 이런 냄새를 모르고 평생 사는 사람도 있겠지만, 전혀 관련이 없는 것은 아닐 것이다. 그저 우연일 뿐이다. 아내를 박대하는 김 첨지의 모습... 요새 같으면 간이 배 밖으로 튀어나온 남자겠지만, 그래도 그 애정은 더 진한 것일 수도 있다.
[작가 소개]
현 진 건(玄鎭健, 1900-1943) : 소설가. 한국 사실주의 단편소설의 기틀을 다진 작가이다. 본관은 연주(延州). 아호는 빙허(憑虛). 1920년대 전반기에는 자전적 요소가 강한 개인적 체험소설인 <빈처> <술 권하는 사회>, 성(性)의 문제와 애정문제를 다룬 <B사감과 러브레터> <새빨간 웃음> 등이 있으며 1920년대 중반 이후에는 <피아노> <우편국에서> <불> <고향> 등 세태에의 관심과 식민지 상황하의 현실인식이 두드러진 작품을 많이 발표했다. <운수 좋은 날>도 이러한 계열에 속하는 작품이다. 1930년대 이후에는 역사의식과 예언주의적 문학관에 근거한 역사소설 중심의 <무영탑> <흑치상지(黑齒常之)> <선화공주> 등 장편소설을 발표했다.
새침하게 흐린 품이 눈이 올 듯하더니 눈은 아니 오고 얼다가 만 비가 추적추적 내리었다.
이날이야말로 동소문 안에서 인력거꾼 노릇을 하는 김 첨지에게는 오래간만에도 닥친 운수 좋은 날이었다. 문안에(거기도 문밖은 아니지만) 들어간답시는 앞집 마나님을 전찻길까지 모셔다 드린 것을 비롯으로 행여나 손님이 있을까 하고 정류장에서 어정어정하며 내리는 사람 하나하나에게 거의 비는 듯한 눈결을 보내고 있다가 마침내 교원인 듯한 양복장이를 동광학교(東光學校)까지 태워다 주기로 되었다.
첫번에 삼십 전, 둘째 번에 오십 전 - 아침 댓바람에 그리 흔치 않은 일이었다. 그야말로 재수가 옴붙어서 근 열흘 동안 돈 구경도 못한 김 첨지는 십 전짜리 백통화 서 푼, 또는 다섯 푼이 찰깍하고 손바닥에 떨어질 제 거의 눈물을 흘릴 만큼 기뻤었다. 더구나 이날 이때에 이 팔십 전이라는 돈이 그에게 얼마나 유용한지 몰랐다. 컬컬한 목에 모주 한 잔도 적실 수 있거니와 그보다도 앓는 아내에게 설렁탕 한 그릇도 사다줄 수 있음이다.
그의 아내가 기침으로 쿨럭거리기는 벌써 달포가 넘었다. 조밥도 굶기를 먹다시피 하는 형편이니 물론 약 한 첩 써 본 일이 없다. 구태여 쓰려면 못 쓸 바도 아니로되 그는 병이란 놈에게 약을 주어 보내면 재미를 붙여서 자꾸 온다는 자기의 신조(信條)에 어디까지 충실하였다. 따라서 의사에게 보인 적이 없으니 무슨 병인지는 알 수 없으되 반듯이 누워 가지고, 일어나기는 새로 모로도 못 눕는걸 보면 중증은 중증인 듯. 병이 이대도록 심해지기는 열흘 전에 조밥을 먹고 체한 때문이다.
그때도 김 첨지가 오래간만에 돈을 얻어서 좁쌀 한 되와 십 전짜리 나무 한 단을 사다 주었더니 김 첨지의 말에 의지하면 그 오라질 년이 천방지축(天方地軸)으로 남비에 대고 끓였다. 마음은 급하고 불길은 달지 않아 채 익지도 않은 것을 그 오라질 년이 숟가락은 고만두고 손으로 움켜서 두 뺨에 주먹덩이 같은 혹이 불거지도록 누가 빼앗을 듯이 처박질 하더니만 그날 저녁부터 가슴이 땅긴다, 배가 켕긴다고 눈을 홉뜨고 지랄병을 하였다. 그때 김 첨지는 열화와 같이 성을 내며,
“에이, 오라질 년, 조롱복은 할 수가 없어, 못 먹어 병, 먹어서 병, 어쩌란 말이야! 왜 눈을 바루 뜨지 못해!”하고 김 첨지는 앓는 이의 뺨을 한 번 후려갈겼다. 홉뜬 눈은 조금 바루어졌건만 이슬이 맺히었다. 김 첨지의 눈시울도 뜨끈뜨끈하였다.
이 환자가 그러고도 먹는 데는 물리지 않았다. 사흘 전부터 설렁탕 국물이 마시고 싶다고 남편을 졸랐다.
“이런 오라질 년! 조밥도 못 먹는 년이 설렁탕은, 또 처먹고 지랄병을 하게.”라고, 야단을 쳐보았건만, 못 사주는 마음이 시원치는 않았다.
인제 설렁탕을 사줄 수도 있다. 앓는 어미 곁에서 배고파 보채는 개똥이(세 살먹이)에게 죽을 사줄 수도 있다. - 팔십 전을 손에 쥔 김 첨지의 마음은 푼푼하였다. 그러나 그의 행운은 그걸로 그치지 않았다. 땀과 빗물이 섞여 흐르는 목덜미를 기름주머니가 다 된 왜목 수건으로 닦으며, 그 학교 문을 돌아나올 때였다. 뒤에서 <인력거!> 하고 부르는 소리가 난다. 자기를 불러 멈춘 사람이 그 학교 학생인 줄 김 첨지는 한 번 보고 짐작할 수 있었다. 그 학생은 다짜고짜로, “남대문 정거장까지 얼마요?”라고, 물었다.
아마도 그 학교 기숙사에 있는 이로 동기방학을 이용하여 귀향하려 함이리라. 오늘 가기로 작정은 하였건만 비는 오고, 짐은 있고 해서 어찌할 줄 모르다가 마침 김 첨지를 보고 뛰어나왔음이리라. 그렇지 않으면 왜 구두를 채 신지 못해서 질질 끌고, 비록 <고구라> 양복일망정 노박이로 비를 맞으며 김첨지를 뒤쫓아 나왔으랴.
“남대문 정거장까지 말씀입니까.”하고 김 첨지는 잠깐 주저하였다. 그는 이 우중에 우장도 없이 그 먼 곳을 철벅거리고 가기가 싫었음일까? 처음 것, 둘째 것으로 그만 만족하였음일까? 아니다, 결코 아니다. 이상하게도 꼬리를 맞물고 덤비는 이 행운 앞에 조금 겁이 났음이다.그리고 집을 나올 제 아내의 부탁이 마음에 켕기었다. - 앞집 마나님한테서 부르러 왔을 제 병인은 그 뼈만 남은 얼굴에 유일의 생물 같은 유달리 크고 움폭한 눈에 애걸하는 빛을 띠우며, “오늘은 나가지 말아요. 제발 덕분에 집에 붙어있어요. 내가 이렇게 아픈데……”라고, 모기 소리같이 중얼거리고 숨을 걸그렁걸그렁 하였다.
그때에 김 첨지는 대수롭지 않은 듯이, “압다, 젠장맞을 년, 별 빌어먹을 소리를 다 하네. 맞붙들고 앉았으면 누가 먹여 살릴 줄 알아.”하고, 훌쩍 뛰어나오려니까 환자는 붙잡을 듯이 팔을 내저으며, “나가지 말라도 그래, 그러면 일찌기 들어와요.”하고, 목메인 소리가 뒤를 따랐다.
정거장까지 가잔 말을 들은 순간에 경련적으로 떠는 손, 유달리 큼직한 눈, 울 듯한 아내의 얼굴이 김 첨지의 눈앞에 어른어른하였다. “그래 남대문 정거장까지 얼마란 말이요?”하고 학생은 초조한 듯이 인력거꾼의 얼굴을 바라보며 혼잣말같이, “인천 차가 열 한 점에 있고, 그 다음에는 새로 두 점이든가.”라고, 중얼거린다.
“일 원 오십 전만 줍시요.” 이 말이 저도 모를 사이에 불쑥 김 첨지의 입에서 떨어졌다. 제 입으로 부르고도 스스로 그 엄청난 돈 액수에 놀래었다. 한꺼번에 이런 금액을 불러라도 본 지가 그 얼마만인가! 그러자 그 돈 벌 용기가 병자에 대한 염려를 사르고 말았다. 설마 오늘 내로 어떠랴 싶었다. 무슨 일이 있더라도 제일 제이의 행운을 곱친 것보다도 오히려 갑절이 많은 이 행운을 놓칠 수 없다 하였다.
“일 원 오십 전은 너무 과한데.” 이런 말을 하며 학생은 고개를 기웃하였다.
“아니올시다. 잇수로 치면 여기서 거기가 시오리가 넘는답니다. 또 이런 진 날에 좀더 주셔야지요.”하고 빙글빙글 웃는 차부의 얼굴에는 숨길 수 없는 기쁨이 넘쳐 흘렀다.
“그러면 달라는 대로 줄 터이니 빨리 가요.” 관대한 어린 손님은 그런 말을 남기고 총총히 옷도 입고 짐도 챙기러 갈 데로 갔다.
그 학생을 태우고 나선 김 첨지의 다리는 이상하게 거뿐하였다. 달음질을 한다느니보다 거의 나는 듯하였다. 바퀴도 어떻게 속히 도는지 군다느니보다 마치 얼음을 지쳐나가는 <스케이트> 모양으로 미끄러져 가는 듯하였다. 얼은 땅에 비가 내려 미끄럽기도 하였지만.
이윽고 끄는 이의 다리는 무거워졌다. 자기 집 가까이 다다른 까닭이다. 새삼스러운 염려가 그의 가슴을 눌렀다. <오늘은 나가지 말아요. 내가 이렇게 아픈데!> 이런 말이 잉잉 그의 귀에 울렸다. 그리고 병자의 움쑥 들어간 눈이 원망하는 듯이 자기를 노리는 듯하였다. 그러자 엉엉하고 우는 개똥이의 곡성을 들은 듯싶다. 딸국딸국 하고 숨 모으는 소리도 나는 듯싶다.“왜 이리우, 기차 놓치겠구먼.”하고 탄 이의 초조한 부르짖음이 간신히 그의 귀에 들어왔다. 언뜻 깨달으니 김 첨지는 인력거를 쥔 채 길 한복판에 엉거주춤 멈춰있지 않은가.
“예, 예.”하고, 김 첨지는 또다시 달음질하였다. 집이 차차 멀어갈수록 김 첨지의 걸음에는 다시금 신이 나기 시작하였다. 다리를 재게 놀려야만 쉴새없이 자기의 머리에 떠오르는 모든 근심과 걱정을 잊을 듯이.
정거장까지 끌어다주고 그 깜짝 놀란 일 원 오십 전을 정말 제 손에 쥠에, 제 말마따나 십 리나 되는 길을 비를 맞아 가며 질퍽거리고 온 생각은 아니하고, 거저나 얻은 듯이 고마왔다. 졸부나 된 듯이 기뻤다. 제자식 뻘밖에 안되는 어린 손님에게 몇 번 허리를 굽히며, “안녕히 다녀옵시요.”라고 깍듯이 재우쳤다.
그러나 빈 인력거를 털털거리며 이 우중에 돌아갈 일이 꿈밖이었다. 노동으로 하여 흐른 땀이 식어지자 굶주린 창자에서, 물 흐르는 옷에서 어슬어슬 한기가 솟아나기 비롯하매 일 원 오십 전이란 돈이 얼마나 괜찮고 괴로운 것인 줄 절절히 느끼었다. 정거장을 떠나는 그의 발길은 힘 하나 없었다. 온몸이 옹송그려지며 당장 그 자리에 엎어져 못 일어날 것 같았다.
“젠장맞을 것! 이 비를 맞으며 빈 인력거를 털털거리고 돌아를 간담. 이런 빌어먹을, 제 할미를 붙을 비가 왜 남의 상판을 딱딱 때려!”
그는 몹시 홧증을 내며 누구에게 반항이나 하는 듯이 게걸거렸다. 그럴 즈음에 그의 머리엔 또 새로운 광명이 비쳤나니 그것은 <이러구 갈 게 아니라 이 근처를 빙빙 돌며 차 오기를 기다리면 또 손님을 태우게 될는지도 몰라>란 생각이었다. 오늘 운수가 괴상하게도 좋으니까 그런 요행이 또한번 없으리라고 누가 보증하랴. 꼬리를 굴리는 행운이 꼭 자기를 기다리고 있다고 내기를 해도 좋을 만한 믿음을 얻게 되었다. 그렇다고 정거장 인력거꾼의 등살이 무서우니 정거장 앞에 섰을 수는 없었다.
그래 그는 이전에도 여러 번 해본 일이라 바로 정거장 앞 전차 정류장에서 조금 떨어지게, 사람 다니는 길과 전찻길 틈에 인력거를 세워놓고 자기는 그 근처를 빙빙 돌며 형세를 관망하기로 하였다. 얼마만에 기차는 왔고, 수십 명이나 되는 손이 정류장으로 쏟아져 나왔다. 그 중에서 손님을 물색하는 김 첨지의 눈엔 양머리에 뒤축 높은 구두를 신고 <망토>까지 두른 기생 퇴물인 듯, 난봉 여학생인 듯한 여편네의 모양이 띄었다. 그는 슬근슬근 그 여자의 곁으로 다가들었다.
“아씨, 인력거 아니 타시랍시요?”
그 여학생인지 뭔지가 한참은 매우 탯갈을 빼며 입술을 꼭 다문 채 김 첨지를 거들떠보지도 않았다. 김 첨지는 구걸하는 거지나 무엇같이 연해연방 그의 기색을 살피며, “아씨, 정거장 애들보담 아주 싸게 모셔다 드리겠읍니다. 댁이 어디신가요.”하고, 추근추근하게도 그 여자의 들고 있는 일본식 버들고리짝에 제 손을 대었다.
“왜 이래, 남 귀치않게.” 소리를 벽력같이 지르고는 돌아선다. 김 첨지는 어랍시요 하고 물러섰다.
전차는 왔다. 김 첨지는 원망스럽게 전차 타는 이를 노리고 있었다. 그러나 그의 예감(豫感)은 틀리지 않았다. 전차가 빡빡하게 사람을 싣고 움직이기 시작하였을 때 타고 남은 손 하나이 있었다. 굉장하게 큰 가방을 들고 있는걸 보면 아마 붐비는 차 안에 짐이 크다 하여 차장에게 밀려내려온 눈치였다. 김 첨지는 대어섰다.
“인력거를 타시랍시요.”
한동안 값으로 승강이를 하다가 육십 전에 인사동까지 태워다주기로 하였다. 인력거가 무거워지매 그의 몸은 이상하게도 가벼워졌고 그리고 또 인력거가 가벼워지니 몸은 다시금 무거워졌건만 이번에는 마음조차 초조해 온다. 집의 광경이 자꾸 눈앞에 어른거리어 인제 요행을 바랄 여유도 없었다. 나무 등걸이나 무엇 같고 제 것 같지도 않은 다리를 연해 꾸짖으며 갈팡질팡 뛰는 수밖에 없었다.
저놈의 인력거군이 저렇게 술이 취해가지고 이 진 땅에 어찌 가노, 라고 길 가는 사람이 걱정을 하리만큼 그의 걸음은 황급하였다. 흐리고 비오는 하늘은 어둠침침하게 벌써 황혼에 가까운 듯하다. 창경원 앞까지 다달아서야 그는 턱에 닿은 숨을 돌리고 걸음도 늦추잡았다. 한 걸음 두 걸음 집이 가까와올수록 그의 마음조차 괴상하게 누그러웠다. 그런데 이 누그러움은 안심에서 오는 게 아니요, 자기를 덮친 무서운 불행을 빈틈없이 알게 될 때가 박두한 것을 두려워하는 마음에서 오는 것이다.
그는 불행에 다닥치기 전 시간을 얼마쯤이라도 늘리려고 버르적거렸다. 기적(奇蹟)에 가까운 벌이를 하였다는 기쁨을 할 수 있으면 오래 지니고 싶었다. 그는 두리번두리번 사면을 살피었다. 그 모양은 마치 자기 집 - 곧 불행을 향하고 달려가는 제 다리를 제 힘으로는 도저히 어찌할 수 없으니 누구든지 나를 좀 잡아 다고, 구해 다고 하는 듯하였다.
그럴 즈음에 마침 길가 선술집에서 그의 친구 치삼이가 나온다. 그의 우글우글 살찐 얼굴에 주홍이 돋는 듯, 온 턱과 뺨을 시커멓게 구레나룻이 덮였거늘, 노르탱탱한 얼굴이 바짝 말라서 여기저기 고랑이 패고, 수염도 있대야 턱밑에만 마치 솔잎 송이를 거꾸로 붙여놓은 듯한 김 첨지의 풍채하고는 기이한 대상을 짓고 있었다.
“여보게 김 첨지, 자네 문안 들어갔다 오는 모양일세그려. 돈 많이 벌었을 테니 한 잔 빨리게.”
뚱뚱보는 말라깽이를 보든 맡에 부르짖었다. 그 목소리는 몸짓과 딴판으로 연하고 싹싹하였다. 김 첨지는 이 친구를 만난 게 어떻게 반가운지 몰랐다. 자기를 살려준 은인이나 무엇같이 고맙기도 하였다.
“자네는 벌써 한잔 한 모양일세그려. 자네도 오늘 재미가 좋아보이.”하고, 김 첨지는 얼굴을 펴서 웃었다.
“압다, 재미 안 좋다고 술 못 먹을 낸가. 그런데 여보게, 자네 왼몸이 어째 물독에 빠진 새앙쥐 같은가? 어서 이리 들어와 말리게.”
선술집은 훈훈하고 뜨뜻하였다. 추어탕을 끓이는 솥뚜껑을 열 적마다 뭉게뭉게 떠오르는 흰 김, 석쇠에서 뻐지짓뻐지짓 구워지는 너비아니 구이며 제육이며 간이며 콩팥이며 북어며 빈대떡……이 너저분하게 늘어놓인 안주 탁자에 김 첨지는 갑자기 속이 쓰려서 견딜 수 없었다. 마음대로 할 양이면 거기 있는 모든 먹음 먹이를 모조리 깡그리 집어삼켜도 시원치 않았다. 하되 배고픈 이는 위선 분량 많은 빈대떡 두 개를 쪼이기도 하고 추어탕을 한 그릇 청하였다.
주린 창자는 음식맛을 보더니 더욱더욱 비어지며 자꾸자꾸 들이라들이라 하였다. 순식간에 두부와 미꾸리 든 국 한 그릇을 그냥 물같이 들이키고 말았다. 세째 그릇을 받아들었을 제 데우던 막걸이 곱배기 두 잔이 더웠다. 치삼이와 같이 마시자 원원히 비었던 속이라 찌르르하고 창자에 퍼지며 얼굴이 화끈하였다. 눌러 곱배기 한 잔을 또 마셨다.
김 첨지의 눈은 벌써 개개 풀리기 시작하였다. 석쇠에 얹힌 떡 두 개를 숭덩숭덩 썰어서 볼을 불룩거리며 또 곱배기 두 잔을 부어라 하였다.
치삼은 의아한 듯이 김 첨지를 보며, “여보게 또 붓다니, 벌써 우리가 넉 잔씩 먹었네, 돈이 사십 전일세.”라고 주의시켰다.
“아따 이놈아, 사십 전이 그리 끔찍하냐. 오늘 내가 돈을 막 벌었어. 참 오늘 운수가 좋았느니.”
“그래 얼마를 벌었단 말인가?”
“삼십 원을 벌었어, 삼십 원을! 이런 젠장맞을 술을 왜 안부어……괜찮다 괜찮다, 막 먹어도 상관이 없어. 오늘 돈 산더미같이 벌었는데.”
“어, 이 사람 취했군, 그만두세.”
“이놈아, 이걸 먹고 취할 내냐, 어서 더 먹어.”하고는 치삼의 귀를 잡아채며 취한 이는 부르짖었다. 그리고 술을 붓는 열 다섯 살 됨직한 중대가리에게로 달려들며, “이놈, 오라질 놈, 왜 술을 붓지 않어.”라고 야단을 쳤다. 중대가리는 히히 웃고 치삼을 보며 문의하는 듯이 눈짓을 하였다. 주정꾼이 눈치를 알아보고 화를 버럭내며, “에미를 붙을 이 오라질 놈들 같으니, 이놈 내가 돈이 없을 줄 알고.”하자마자 허리춤을 훔칫훔칫 하더니 일 원짜리 한 장을 꺼내어 중대가리 앞에 펄쩍 집어던졌다. 그 사품에 몇 푼 은전이 잘그랑 하며 떨어진다.
“여보게 돈 떨어졌네, 왜 돈을 막 끼얹나.” 이런 말을 하며 일변 돈을 줍는다. 김 첨지는 취한 중에도 돈의 거처를 살피는 듯이 눈을 크게 떠서 땅을 내려다보다가 불시에 제 하는 짓이 너무 더럽다는 듯이 고개를 소스라치자 더욱 성을 내며, “봐라 봐! 이 더러운 놈들아, 내가 돈이 없나, 다리뼉다구를 꺾어놓을 놈들 같으니.”하고 치삼의 주워주는 돈을 받아, “이 원수엣 돈! 이 육시를 할 돈!”하면서, 풀매질을 친다. 벽에 맞아 떨어진 돈은 다시 술 끓이는 양푼에 떨어지며 정당한 매를 맞는다는 듯이 쨍하고 울었다.
곱배기 두 잔은 또 부어질 겨를도 없이 말려가고 말았다. 김 첨지는 입술과 수염에 붙은 술을 빨아들이고 나서 매우 만족한 듯이 그 솔잎 송이 수염을 쓰다듬으며, “또 부어, 또 부어.”라고, 외쳤다.
또 한 잔 먹고 나서 김 첨지는 치삼의 어깨를 치며 문득 껄껄 웃는다. 그 웃음 소리가 어떻게 컸는지 술집에 있는 이의 눈은 모두 김 첨지에게로 몰리었다. 웃는 이는 더욱 웃으며, “여보게 치삼이, 내 우스운 이야기 하나 할까. 오늘 손을 태고 정거장에까지 가지 않았겠나.”
“그래서.”
“갔다가 그저 오기가 안 됐데그려. 그래 전차 정류장에서 어름어름하며 손님 하나를 태울 궁리를 하지 않았나. 거기 마침 마나님이신지 여학생님이신지 - 요새야 어디 논다니와 아가씨를 구별할 수가 있던가 - <망토>를 두르고 비를 맞고 서 있겠지. 슬근슬근 가까이 가서 인력거 타시랍시요 하고 손가방을 받으랴니까 내 손을 탁 뿌리치고 홱 돌아서더니만 <왜 남을 이렇게 귀찮게 굴어!> 그 소리야말로 꾀꼬리 소리지, 허허!”
김 첨지는 교묘하게도 정말 꾀꼬리 같은 소리를 내었다. 모든 사람은 일시에 웃었다.
“빌어먹을 깍쟁이 같은 년, 누가 저를 어쩌나, <왜 남을 귀찮게 굴어!> 어이구 소리가 처신도 없지, 허허.”
웃음 소리들은 높아졌다. 그러나 그 웃음 소리들이 사라지기 전에 김 첨지는 훌쩍훌쩍 울기 시작하였다.
치삼은 어이없이 주정뱅이를 바라보며, “금방 웃고 지랄을 하더니 우는 건 또 무슨 일인가.”
김 첨지는 연해 코를 들여마시며, “우리 마누라가 죽었다네.”
“뭐, 마누라가 죽다니, 언제?”
“이놈아 언제는. 오늘이지.”
“엑기 미친 놈, 거짓말 말아.”
“거짓말은 왜, 참말로 죽었어, 참말로... 마누라 시체를 집어 뻐들쳐놓고 내가 술을 먹다니, 내가 죽일 놈이야, 죽일 놈이야.”하고 김 첨지는 엉엉 소리를 내어 운다.
치삼은 흥이 조금 깨어지는 얼굴로, “원 이 사람이, 참말을 하나 거짓말을 하나. 그러면 집으로 가세, 가.”하고 우는 이의 팔을 잡아당기었다.
치삼의 끄는 손을 뿌리치더니 김 첨지는 눈물이 글썽글썽한 눈으로 싱그레 웃는다.
“죽기는 누가 죽어.”하고 득의가 양양.
“죽기는 왜 죽어, 생때같이 살아만 있단다. 그 오라질 년이 밥을 죽이지. 인제 나한테 속았다.”하고 어린애 모양으로 손뼉을 치며 웃는다.
“이 사람이 정말 미쳤단 말인가. 나도 아주먼네가 앓는단 말은 들었는데.”하고, 치삼이도 어느 불안을 느끼는 듯이 김 첨지에게 또 돌아가라고 권하였다.
“안 죽었어, 안 죽었대도그래.”
김 첨지는 홧증을 내며 확신있게 소리를 질렀으되 그 소리엔 안 죽은 것을 믿으려고 애쓰는 가락이 있었다. 기어이 일 원어치를 채워서 곱배기 한 잔씩 더 먹고 나왔다. 궂은 비는 의연히 추적추적 내린다.
김 첨지는 취중에도 설렁탕을 사가지고 집에 다달았다. 집이라 해도 물론 셋집이요, 또 집 전체를 세든 게 아니라 안과 뚝떨어진 행랑방 한 간을 빌려 든 것인데 물을 길어대고 한 달에 일 원씩 내는 터이다. 만일 김 첨지가 주기를 띠지 않았던들 한 발을 대문에 들여놓았을 제 그곳을 지배하는 무시무시한 정적(靜寂) - 폭풍우가 지나간 뒤의 바다 같은 정적에 다리가 떨렸으리라.
쿨룩거리는 기침 소리도 들을 수 없다. 그르렁거리는 숨소리조차 들을 수 없다. 다만 이 무덤같은 침묵을 깨뜨리는 - 깨뜨린다느니보다 한층 더 침묵을 깊게 하고 불길하게 하는 빡빡하는 그윽한 소리, 어린애의 젖 빠는 소리가 날 뿐이다. 만일 청각(聽覺)이 예민한 이 같으면 그 빡빡 소리는 빨 따름이요, 꿀떡꿀떡 하고 젖 넘어가는 소리가 없으니 빈 젖을 빤다는 것도 짐작할는지 모르리라.
혹은 김 첨지도 이 불길한 침묵을 짐작했는지도 모른다. 그렇지 않으면 대문에 들어서자마자 전에 없이, “이 난장 맞을 년, 남편이 들어오는데 나와보지도 않아, 이 오라질 년.”이라고 고함을 친 게 수상하다. 이 고함이야말로 제 몸을 엄습해오는 무시무시한 증을 쫓아버리려는 허장성세(虛張聲勢)인 까닭이다.
하여간 김 첨지는 방문을 왈칵 열었다. 구역을 나게 하는 추기 - 떨어진 삿자리 밑에서 나온 먼지내, 빨지 않은 기저귀에서 나는 똥내와 오줌내, 가지각색 때가 케케히 앉은 옷내, 병인의 땀 썩은 내가 섞인 추기가 무딘 김 첨지의 코를 찔렀다.
방안에 들어서며 설렁탕을 한구석에 놓을 사이도 없이 주정군은 목청을 있는 대로 다 내어 호통을 쳤다.
“이런 오라질 년, 주야장천(晝夜長川) 누워만 있으면 제일이야! 남편이 와도 일어나지를 못해.”라는 소리와 함께 발길로 누운 이의 다리를 몹시 찼다. 그러나 발길에 채이는 건 사람의 살이 아니고 나무등걸과 같은 느낌이 있었다. 이때에 빽빽 소리가 응아 소리로 변하였다. 개똥이가 물었던 젖을 빼어놓고 운다. 운대도 온 얼굴을 찡그려 붙여서, 운다는 표정을 할 뿐이다. 응아 소리도 입에서 나는 게 아니고 마치 뱃속에서 나는 듯하였다. 울다가 울다가 목도 잠겼고 또 울 기운조차 시진한 것 같다.
발로 차도 그 보람이 없는 걸 보자 남편은 아내의 머리맡으로 달려들어 그야말로 까치집 같은 환자의 머리를 꺼들어 흔들며, “이 년아, 말을 해, 말을! 입이 붙었어, 이 오라질 년!”
“…”
“으응, 이것 봐, 아무 말이 없네.”
“…”
“이년아, 죽었단 말이냐, 왜 말이 없어.”
“…”
“으응. 또 대답이 없네, 정말 죽었나버이.”
이러다가 누운 이의 흰 창을 덮은, 위로 치뜬 눈을 알아보자마자, “이 눈깔! 이 눈깔! 왜 나를 바라보지 못하고 천정만 보느냐, 응.”하는 말 끝엔 목이 메었다. 그러자 산 사람의 눈에서 떨어진 닭의 똥 같은 눈물이 죽은 이의 뻣뻣한 얼굴을 어룽어룽 적시었다. 문득 김 첨지는 미칠 듯이 제 얼굴을 죽은 이의 얼굴에 한테 비비대며 중얼거렸다.
“설렁탕을 사다놓았는데 왜 먹지를 못하니, 왜 먹지를 못하니... 괴상하게도 오늘은! 운수가 좋더니만... ”

View File

@ -0,0 +1,175 @@
This file was derived from
http://www.ibrary.co.kr/index.php/book-list/short-stories/34-short-stories-korean/150-2008-04-20-13-22-32
--------
[소개]
잔인한 운명은 이렇게 인간을 조롱하곤 한다. 우리가 평소 마음 속 저 깊은 곳에 움켜쥐고 있던 자존심 따위는 어느 한 순간 전혀 무용지물이란 것이 드러나고 만다. 하기야 이렇게 삶의 한 순간, 눈 깜짝할 새에 우리를 후려 갈기고 지나가는 그 진실이 미래의 어느날에는 또 남김없이 우리 눈 앞에 펼쳐질지도 모른다. 죽음을 앞둔 사람들에게는 자신의 삶 전체가 한 순간에 다시 보인다는 그런 얘기도 있던데...
다시 읽어보니 끔찍한 생각도 든다. 식민지 시대의 암울한 삶, 그 끈끈한 냄새를 피할 수 없다. 21세기를 사는 우리들에겐 그런 냄새는 아예 인연이 없는 것처럼 느껴질 수도 있을 것이다. 그러나 과연 그럴까? 이런 냄새를 모르고 평생 사는 사람도 있겠지만, 전혀 관련이 없는 것은 아닐 것이다. 그저 우연일 뿐이다. 아내를 박대하는 김 첨지의 모습... 요새 같으면 간이 배 밖으로 튀어나온 남자겠지만, 그래도 그 애정은 더 진한 것일 수도 있다.
[작가 소개]
현 진 건(玄鎭健, 1900-1943) : 소설가. 한국 사실주의 단편소설의 기틀을 다진 작가이다. 본관은 연주(延州). 아호는 빙허(憑虛). 1920년대 전반기에는 자전적 요소가 강한 개인적 체험소설인 <빈처> <술 권하는 사회>, 성(性)의 문제와 애정문제를 다룬 <B사감과 러브레터> <새빨간 웃음> 등이 있으며 1920년대 중반 이후에는 <피아노> <우편국에서> <불> <고향> 등 세태에의 관심과 식민지 상황하의 현실인식이 두드러진 작품을 많이 발표했다. <운수 좋은 날>도 이러한 계열에 속하는 작품이다. 1930년대 이후에는 역사의식과 예언주의적 문학관에 근거한 역사소설 중심의 <무영탑> <흑치상지(黑齒常之)> <선화공주> 등 장편소설을 발표했다.
새침하게 흐린 품이 눈이 올 듯하더니 눈은 아니 오고 얼다가 만 비가 추적추적 내리었다.
이날이야말로 동소문 안에서 인력거꾼 노릇을 하는 김 첨지에게는 오래간만에도 닥친 운수 좋은 날이었다. 문안에(거기도 문밖은 아니지만) 들어간답시는 앞집 마나님을 전찻길까지 모셔다 드린 것을 비롯으로 행여나 손님이 있을까 하고 정류장에서 어정어정하며 내리는 사람 하나하나에게 거의 비는 듯한 눈결을 보내고 있다가 마침내 교원인 듯한 양복장이를 동광학교(東光學校)까지 태워다 주기로 되었다.
첫번에 삼십 전, 둘째 번에 오십 전 - 아침 댓바람에 그리 흔치 않은 일이었다. 그야말로 재수가 옴붙어서 근 열흘 동안 돈 구경도 못한 김 첨지는 십 전짜리 백통화 서 푼, 또는 다섯 푼이 찰깍하고 손바닥에 떨어질 제 거의 눈물을 흘릴 만큼 기뻤었다. 더구나 이날 이때에 이 팔십 전이라는 돈이 그에게 얼마나 유용한지 몰랐다. 컬컬한 목에 모주 한 잔도 적실 수 있거니와 그보다도 앓는 아내에게 설렁탕 한 그릇도 사다줄 수 있음이다.
그의 아내가 기침으로 쿨럭거리기는 벌써 달포가 넘었다. 조밥도 굶기를 먹다시피 하는 형편이니 물론 약 한 첩 써 본 일이 없다. 구태여 쓰려면 못 쓸 바도 아니로되 그는 병이란 놈에게 약을 주어 보내면 재미를 붙여서 자꾸 온다는 자기의 신조(信條)에 어디까지 충실하였다. 따라서 의사에게 보인 적이 없으니 무슨 병인지는 알 수 없으되 반듯이 누워 가지고, 일어나기는 새로 모로도 못 눕는걸 보면 중증은 중증인 듯. 병이 이대도록 심해지기는 열흘 전에 조밥을 먹고 체한 때문이다.
그때도 김 첨지가 오래간만에 돈을 얻어서 좁쌀 한 되와 십 전짜리 나무 한 단을 사다 주었더니 김 첨지의 말에 의지하면 그 오라질 년이 천방지축(天方地軸)으로 남비에 대고 끓였다. 마음은 급하고 불길은 달지 않아 채 익지도 않은 것을 그 오라질 년이 숟가락은 고만두고 손으로 움켜서 두 뺨에 주먹덩이 같은 혹이 불거지도록 누가 빼앗을 듯이 처박질 하더니만 그날 저녁부터 가슴이 땅긴다, 배가 켕긴다고 눈을 홉뜨고 지랄병을 하였다. 그때 김 첨지는 열화와 같이 성을 내며,
“에이, 오라질 년, 조롱복은 할 수가 없어, 못 먹어 병, 먹어서 병, 어쩌란 말이야! 왜 눈을 바루 뜨지 못해!”하고 김 첨지는 앓는 이의 뺨을 한 번 후려갈겼다. 홉뜬 눈은 조금 바루어졌건만 이슬이 맺히었다. 김 첨지의 눈시울도 뜨끈뜨끈하였다.
이 환자가 그러고도 먹는 데는 물리지 않았다. 사흘 전부터 설렁탕 국물이 마시고 싶다고 남편을 졸랐다.
“이런 오라질 년! 조밥도 못 먹는 년이 설렁탕은, 또 처먹고 지랄병을 하게.”라고, 야단을 쳐보았건만, 못 사주는 마음이 시원치는 않았다.
인제 설렁탕을 사줄 수도 있다. 앓는 어미 곁에서 배고파 보채는 개똥이(세 살먹이)에게 죽을 사줄 수도 있다. - 팔십 전을 손에 쥔 김 첨지의 마음은 푼푼하였다. 그러나 그의 행운은 그걸로 그치지 않았다. 땀과 빗물이 섞여 흐르는 목덜미를 기름주머니가 다 된 왜목 수건으로 닦으며, 그 학교 문을 돌아나올 때였다. 뒤에서 <인력거!> 하고 부르는 소리가 난다. 자기를 불러 멈춘 사람이 그 학교 학생인 줄 김 첨지는 한 번 보고 짐작할 수 있었다. 그 학생은 다짜고짜로, “남대문 정거장까지 얼마요?”라고, 물었다.
아마도 그 학교 기숙사에 있는 이로 동기방학을 이용하여 귀향하려 함이리라. 오늘 가기로 작정은 하였건만 비는 오고, 짐은 있고 해서 어찌할 줄 모르다가 마침 김 첨지를 보고 뛰어나왔음이리라. 그렇지 않으면 왜 구두를 채 신지 못해서 질질 끌고, 비록 <고구라> 양복일망정 노박이로 비를 맞으며 김첨지를 뒤쫓아 나왔으랴.
“남대문 정거장까지 말씀입니까.”하고 김 첨지는 잠깐 주저하였다. 그는 이 우중에 우장도 없이 그 먼 곳을 철벅거리고 가기가 싫었음일까? 처음 것, 둘째 것으로 그만 만족하였음일까? 아니다, 결코 아니다. 이상하게도 꼬리를 맞물고 덤비는 이 행운 앞에 조금 겁이 났음이다.그리고 집을 나올 제 아내의 부탁이 마음에 켕기었다. - 앞집 마나님한테서 부르러 왔을 제 병인은 그 뼈만 남은 얼굴에 유일의 생물 같은 유달리 크고 움폭한 눈에 애걸하는 빛을 띠우며, “오늘은 나가지 말아요. 제발 덕분에 집에 붙어있어요. 내가 이렇게 아픈데……”라고, 모기 소리같이 중얼거리고 숨을 걸그렁걸그렁 하였다.
그때에 김 첨지는 대수롭지 않은 듯이, “압다, 젠장맞을 년, 별 빌어먹을 소리를 다 하네. 맞붙들고 앉았으면 누가 먹여 살릴 줄 알아.”하고, 훌쩍 뛰어나오려니까 환자는 붙잡을 듯이 팔을 내저으며, “나가지 말라도 그래, 그러면 일찌기 들어와요.”하고, 목메인 소리가 뒤를 따랐다.
정거장까지 가잔 말을 들은 순간에 경련적으로 떠는 손, 유달리 큼직한 눈, 울 듯한 아내의 얼굴이 김 첨지의 눈앞에 어른어른하였다. “그래 남대문 정거장까지 얼마란 말이요?”하고 학생은 초조한 듯이 인력거꾼의 얼굴을 바라보며 혼잣말같이, “인천 차가 열 한 점에 있고, 그 다음에는 새로 두 점이든가.”라고, 중얼거린다.
“일 원 오십 전만 줍시요.” 이 말이 저도 모를 사이에 불쑥 김 첨지의 입에서 떨어졌다. 제 입으로 부르고도 스스로 그 엄청난 돈 액수에 놀래었다. 한꺼번에 이런 금액을 불러라도 본 지가 그 얼마만인가! 그러자 그 돈 벌 용기가 병자에 대한 염려를 사르고 말았다. 설마 오늘 내로 어떠랴 싶었다. 무슨 일이 있더라도 제일 제이의 행운을 곱친 것보다도 오히려 갑절이 많은 이 행운을 놓칠 수 없다 하였다.
“일 원 오십 전은 너무 과한데.” 이런 말을 하며 학생은 고개를 기웃하였다.
“아니올시다. 잇수로 치면 여기서 거기가 시오리가 넘는답니다. 또 이런 진 날에 좀더 주셔야지요.”하고 빙글빙글 웃는 차부의 얼굴에는 숨길 수 없는 기쁨이 넘쳐 흘렀다.
“그러면 달라는 대로 줄 터이니 빨리 가요.” 관대한 어린 손님은 그런 말을 남기고 총총히 옷도 입고 짐도 챙기러 갈 데로 갔다.
그 학생을 태우고 나선 김 첨지의 다리는 이상하게 거뿐하였다. 달음질을 한다느니보다 거의 나는 듯하였다. 바퀴도 어떻게 속히 도는지 군다느니보다 마치 얼음을 지쳐나가는 <스케이트> 모양으로 미끄러져 가는 듯하였다. 얼은 땅에 비가 내려 미끄럽기도 하였지만.
이윽고 끄는 이의 다리는 무거워졌다. 자기 집 가까이 다다른 까닭이다. 새삼스러운 염려가 그의 가슴을 눌렀다. <오늘은 나가지 말아요. 내가 이렇게 아픈데!> 이런 말이 잉잉 그의 귀에 울렸다. 그리고 병자의 움쑥 들어간 눈이 원망하는 듯이 자기를 노리는 듯하였다. 그러자 엉엉하고 우는 개똥이의 곡성을 들은 듯싶다. 딸국딸국 하고 숨 모으는 소리도 나는 듯싶다.“왜 이리우, 기차 놓치겠구먼.”하고 탄 이의 초조한 부르짖음이 간신히 그의 귀에 들어왔다. 언뜻 깨달으니 김 첨지는 인력거를 쥔 채 길 한복판에 엉거주춤 멈춰있지 않은가.
“예, 예.”하고, 김 첨지는 또다시 달음질하였다. 집이 차차 멀어갈수록 김 첨지의 걸음에는 다시금 신이 나기 시작하였다. 다리를 재게 놀려야만 쉴새없이 자기의 머리에 떠오르는 모든 근심과 걱정을 잊을 듯이.
정거장까지 끌어다주고 그 깜짝 놀란 일 원 오십 전을 정말 제 손에 쥠에, 제 말마따나 십 리나 되는 길을 비를 맞아 가며 질퍽거리고 온 생각은 아니하고, 거저나 얻은 듯이 고마왔다. 졸부나 된 듯이 기뻤다. 제자식 뻘밖에 안되는 어린 손님에게 몇 번 허리를 굽히며, “안녕히 다녀옵시요.”라고 깍듯이 재우쳤다.
그러나 빈 인력거를 털털거리며 이 우중에 돌아갈 일이 꿈밖이었다. 노동으로 하여 흐른 땀이 식어지자 굶주린 창자에서, 물 흐르는 옷에서 어슬어슬 한기가 솟아나기 비롯하매 일 원 오십 전이란 돈이 얼마나 괜찮고 괴로운 것인 줄 절절히 느끼었다. 정거장을 떠나는 그의 발길은 힘 하나 없었다. 온몸이 옹송그려지며 당장 그 자리에 엎어져 못 일어날 것 같았다.
“젠장맞을 것! 이 비를 맞으며 빈 인력거를 털털거리고 돌아를 간담. 이런 빌어먹을, 제 할미를 붙을 비가 왜 남의 상판을 딱딱 때려!”
그는 몹시 홧증을 내며 누구에게 반항이나 하는 듯이 게걸거렸다. 그럴 즈음에 그의 머리엔 또 새로운 광명이 비쳤나니 그것은 <이러구 갈 게 아니라 이 근처를 빙빙 돌며 차 오기를 기다리면 또 손님을 태우게 될는지도 몰라>란 생각이었다. 오늘 운수가 괴상하게도 좋으니까 그런 요행이 또한번 없으리라고 누가 보증하랴. 꼬리를 굴리는 행운이 꼭 자기를 기다리고 있다고 내기를 해도 좋을 만한 믿음을 얻게 되었다. 그렇다고 정거장 인력거꾼의 등살이 무서우니 정거장 앞에 섰을 수는 없었다.
그래 그는 이전에도 여러 번 해본 일이라 바로 정거장 앞 전차 정류장에서 조금 떨어지게, 사람 다니는 길과 전찻길 틈에 인력거를 세워놓고 자기는 그 근처를 빙빙 돌며 형세를 관망하기로 하였다. 얼마만에 기차는 왔고, 수십 명이나 되는 손이 정류장으로 쏟아져 나왔다. 그 중에서 손님을 물색하는 김 첨지의 눈엔 양머리에 뒤축 높은 구두를 신고 <망토>까지 두른 기생 퇴물인 듯, 난봉 여학생인 듯한 여편네의 모양이 띄었다. 그는 슬근슬근 그 여자의 곁으로 다가들었다.
“아씨, 인력거 아니 타시랍시요?”
그 여학생인지 뭔지가 한참은 매우 탯갈을 빼며 입술을 꼭 다문 채 김 첨지를 거들떠보지도 않았다. 김 첨지는 구걸하는 거지나 무엇같이 연해연방 그의 기색을 살피며, “아씨, 정거장 애들보담 아주 싸게 모셔다 드리겠읍니다. 댁이 어디신가요.”하고, 추근추근하게도 그 여자의 들고 있는 일본식 버들고리짝에 제 손을 대었다.
“왜 이래, 남 귀치않게.” 소리를 벽력같이 지르고는 돌아선다. 김 첨지는 어랍시요 하고 물러섰다.
전차는 왔다. 김 첨지는 원망스럽게 전차 타는 이를 노리고 있었다. 그러나 그의 예감(豫感)은 틀리지 않았다. 전차가 빡빡하게 사람을 싣고 움직이기 시작하였을 때 타고 남은 손 하나이 있었다. 굉장하게 큰 가방을 들고 있는걸 보면 아마 붐비는 차 안에 짐이 크다 하여 차장에게 밀려내려온 눈치였다. 김 첨지는 대어섰다.
“인력거를 타시랍시요.”
한동안 값으로 승강이를 하다가 육십 전에 인사동까지 태워다주기로 하였다. 인력거가 무거워지매 그의 몸은 이상하게도 가벼워졌고 그리고 또 인력거가 가벼워지니 몸은 다시금 무거워졌건만 이번에는 마음조차 초조해 온다. 집의 광경이 자꾸 눈앞에 어른거리어 인제 요행을 바랄 여유도 없었다. 나무 등걸이나 무엇 같고 제 것 같지도 않은 다리를 연해 꾸짖으며 갈팡질팡 뛰는 수밖에 없었다.
저놈의 인력거군이 저렇게 술이 취해가지고 이 진 땅에 어찌 가노, 라고 길 가는 사람이 걱정을 하리만큼 그의 걸음은 황급하였다. 흐리고 비오는 하늘은 어둠침침하게 벌써 황혼에 가까운 듯하다. 창경원 앞까지 다달아서야 그는 턱에 닿은 숨을 돌리고 걸음도 늦추잡았다. 한 걸음 두 걸음 집이 가까와올수록 그의 마음조차 괴상하게 누그러웠다. 그런데 이 누그러움은 안심에서 오는 게 아니요, 자기를 덮친 무서운 불행을 빈틈없이 알게 될 때가 박두한 것을 두려워하는 마음에서 오는 것이다.
그는 불행에 다닥치기 전 시간을 얼마쯤이라도 늘리려고 버르적거렸다. 기적(奇蹟)에 가까운 벌이를 하였다는 기쁨을 할 수 있으면 오래 지니고 싶었다. 그는 두리번두리번 사면을 살피었다. 그 모양은 마치 자기 집 - 곧 불행을 향하고 달려가는 제 다리를 제 힘으로는 도저히 어찌할 수 없으니 누구든지 나를 좀 잡아 다고, 구해 다고 하는 듯하였다.
그럴 즈음에 마침 길가 선술집에서 그의 친구 치삼이가 나온다. 그의 우글우글 살찐 얼굴에 주홍이 돋는 듯, 온 턱과 뺨을 시커멓게 구레나룻이 덮였거늘, 노르탱탱한 얼굴이 바짝 말라서 여기저기 고랑이 패고, 수염도 있대야 턱밑에만 마치 솔잎 송이를 거꾸로 붙여놓은 듯한 김 첨지의 풍채하고는 기이한 대상을 짓고 있었다.
“여보게 김 첨지, 자네 문안 들어갔다 오는 모양일세그려. 돈 많이 벌었을 테니 한 잔 빨리게.”
뚱뚱보는 말라깽이를 보든 맡에 부르짖었다. 그 목소리는 몸짓과 딴판으로 연하고 싹싹하였다. 김 첨지는 이 친구를 만난 게 어떻게 반가운지 몰랐다. 자기를 살려준 은인이나 무엇같이 고맙기도 하였다.
“자네는 벌써 한잔 한 모양일세그려. 자네도 오늘 재미가 좋아보이.”하고, 김 첨지는 얼굴을 펴서 웃었다.
“압다, 재미 안 좋다고 술 못 먹을 낸가. 그런데 여보게, 자네 왼몸이 어째 물독에 빠진 새앙쥐 같은가? 어서 이리 들어와 말리게.”
선술집은 훈훈하고 뜨뜻하였다. 추어탕을 끓이는 솥뚜껑을 열 적마다 뭉게뭉게 떠오르는 흰 김, 석쇠에서 뻐지짓뻐지짓 구워지는 너비아니 구이며 제육이며 간이며 콩팥이며 북어며 빈대떡……이 너저분하게 늘어놓인 안주 탁자에 김 첨지는 갑자기 속이 쓰려서 견딜 수 없었다. 마음대로 할 양이면 거기 있는 모든 먹음 먹이를 모조리 깡그리 집어삼켜도 시원치 않았다. 하되 배고픈 이는 위선 분량 많은 빈대떡 두 개를 쪼이기도 하고 추어탕을 한 그릇 청하였다.
주린 창자는 음식맛을 보더니 더욱더욱 비어지며 자꾸자꾸 들이라들이라 하였다. 순식간에 두부와 미꾸리 든 국 한 그릇을 그냥 물같이 들이키고 말았다. 세째 그릇을 받아들었을 제 데우던 막걸이 곱배기 두 잔이 더웠다. 치삼이와 같이 마시자 원원히 비었던 속이라 찌르르하고 창자에 퍼지며 얼굴이 화끈하였다. 눌러 곱배기 한 잔을 또 마셨다.
김 첨지의 눈은 벌써 개개 풀리기 시작하였다. 석쇠에 얹힌 떡 두 개를 숭덩숭덩 썰어서 볼을 불룩거리며 또 곱배기 두 잔을 부어라 하였다.
치삼은 의아한 듯이 김 첨지를 보며, “여보게 또 붓다니, 벌써 우리가 넉 잔씩 먹었네, 돈이 사십 전일세.”라고 주의시켰다.
“아따 이놈아, 사십 전이 그리 끔찍하냐. 오늘 내가 돈을 막 벌었어. 참 오늘 운수가 좋았느니.”
“그래 얼마를 벌었단 말인가?”
“삼십 원을 벌었어, 삼십 원을! 이런 젠장맞을 술을 왜 안부어……괜찮다 괜찮다, 막 먹어도 상관이 없어. 오늘 돈 산더미같이 벌었는데.”
“어, 이 사람 취했군, 그만두세.”
“이놈아, 이걸 먹고 취할 내냐, 어서 더 먹어.”하고는 치삼의 귀를 잡아채며 취한 이는 부르짖었다. 그리고 술을 붓는 열 다섯 살 됨직한 중대가리에게로 달려들며, “이놈, 오라질 놈, 왜 술을 붓지 않어.”라고 야단을 쳤다. 중대가리는 히히 웃고 치삼을 보며 문의하는 듯이 눈짓을 하였다. 주정꾼이 눈치를 알아보고 화를 버럭내며, “에미를 붙을 이 오라질 놈들 같으니, 이놈 내가 돈이 없을 줄 알고.”하자마자 허리춤을 훔칫훔칫 하더니 일 원짜리 한 장을 꺼내어 중대가리 앞에 펄쩍 집어던졌다. 그 사품에 몇 푼 은전이 잘그랑 하며 떨어진다.
“여보게 돈 떨어졌네, 왜 돈을 막 끼얹나.” 이런 말을 하며 일변 돈을 줍는다. 김 첨지는 취한 중에도 돈의 거처를 살피는 듯이 눈을 크게 떠서 땅을 내려다보다가 불시에 제 하는 짓이 너무 더럽다는 듯이 고개를 소스라치자 더욱 성을 내며, “봐라 봐! 이 더러운 놈들아, 내가 돈이 없나, 다리뼉다구를 꺾어놓을 놈들 같으니.”하고 치삼의 주워주는 돈을 받아, “이 원수엣 돈! 이 육시를 할 돈!”하면서, 풀매질을 친다. 벽에 맞아 떨어진 돈은 다시 술 끓이는 양푼에 떨어지며 정당한 매를 맞는다는 듯이 쨍하고 울었다.
곱배기 두 잔은 또 부어질 겨를도 없이 말려가고 말았다. 김 첨지는 입술과 수염에 붙은 술을 빨아들이고 나서 매우 만족한 듯이 그 솔잎 송이 수염을 쓰다듬으며, “또 부어, 또 부어.”라고, 외쳤다.
또 한 잔 먹고 나서 김 첨지는 치삼의 어깨를 치며 문득 껄껄 웃는다. 그 웃음 소리가 어떻게 컸는지 술집에 있는 이의 눈은 모두 김 첨지에게로 몰리었다. 웃는 이는 더욱 웃으며, “여보게 치삼이, 내 우스운 이야기 하나 할까. 오늘 손을 태고 정거장에까지 가지 않았겠나.”
“그래서.”
“갔다가 그저 오기가 안 됐데그려. 그래 전차 정류장에서 어름어름하며 손님 하나를 태울 궁리를 하지 않았나. 거기 마침 마나님이신지 여학생님이신지 - 요새야 어디 논다니와 아가씨를 구별할 수가 있던가 - <망토>를 두르고 비를 맞고 서 있겠지. 슬근슬근 가까이 가서 인력거 타시랍시요 하고 손가방을 받으랴니까 내 손을 탁 뿌리치고 홱 돌아서더니만 <왜 남을 이렇게 귀찮게 굴어!> 그 소리야말로 꾀꼬리 소리지, 허허!”
김 첨지는 교묘하게도 정말 꾀꼬리 같은 소리를 내었다. 모든 사람은 일시에 웃었다.
“빌어먹을 깍쟁이 같은 년, 누가 저를 어쩌나, <왜 남을 귀찮게 굴어!> 어이구 소리가 처신도 없지, 허허.”
웃음 소리들은 높아졌다. 그러나 그 웃음 소리들이 사라지기 전에 김 첨지는 훌쩍훌쩍 울기 시작하였다.
치삼은 어이없이 주정뱅이를 바라보며, “금방 웃고 지랄을 하더니 우는 건 또 무슨 일인가.”
김 첨지는 연해 코를 들여마시며, “우리 마누라가 죽었다네.”
“뭐, 마누라가 죽다니, 언제?”
“이놈아 언제는. 오늘이지.”
“엑기 미친 놈, 거짓말 말아.”
“거짓말은 왜, 참말로 죽었어, 참말로... 마누라 시체를 집어 뻐들쳐놓고 내가 술을 먹다니, 내가 죽일 놈이야, 죽일 놈이야.”하고 김 첨지는 엉엉 소리를 내어 운다.
치삼은 흥이 조금 깨어지는 얼굴로, “원 이 사람이, 참말을 하나 거짓말을 하나. 그러면 집으로 가세, 가.”하고 우는 이의 팔을 잡아당기었다.
치삼의 끄는 손을 뿌리치더니 김 첨지는 눈물이 글썽글썽한 눈으로 싱그레 웃는다.
“죽기는 누가 죽어.”하고 득의가 양양.
“죽기는 왜 죽어, 생때같이 살아만 있단다. 그 오라질 년이 밥을 죽이지. 인제 나한테 속았다.”하고 어린애 모양으로 손뼉을 치며 웃는다.
“이 사람이 정말 미쳤단 말인가. 나도 아주먼네가 앓는단 말은 들었는데.”하고, 치삼이도 어느 불안을 느끼는 듯이 김 첨지에게 또 돌아가라고 권하였다.
“안 죽었어, 안 죽었대도그래.”
김 첨지는 홧증을 내며 확신있게 소리를 질렀으되 그 소리엔 안 죽은 것을 믿으려고 애쓰는 가락이 있었다. 기어이 일 원어치를 채워서 곱배기 한 잔씩 더 먹고 나왔다. 궂은 비는 의연히 추적추적 내린다.
김 첨지는 취중에도 설렁탕을 사가지고 집에 다달았다. 집이라 해도 물론 셋집이요, 또 집 전체를 세든 게 아니라 안과 뚝떨어진 행랑방 한 간을 빌려 든 것인데 물을 길어대고 한 달에 일 원씩 내는 터이다. 만일 김 첨지가 주기를 띠지 않았던들 한 발을 대문에 들여놓았을 제 그곳을 지배하는 무시무시한 정적(靜寂) - 폭풍우가 지나간 뒤의 바다 같은 정적에 다리가 떨렸으리라.
쿨룩거리는 기침 소리도 들을 수 없다. 그르렁거리는 숨소리조차 들을 수 없다. 다만 이 무덤같은 침묵을 깨뜨리는 - 깨뜨린다느니보다 한층 더 침묵을 깊게 하고 불길하게 하는 빡빡하는 그윽한 소리, 어린애의 젖 빠는 소리가 날 뿐이다. 만일 청각(聽覺)이 예민한 이 같으면 그 빡빡 소리는 빨 따름이요, 꿀떡꿀떡 하고 젖 넘어가는 소리가 없으니 빈 젖을 빤다는 것도 짐작할는지 모르리라.
혹은 김 첨지도 이 불길한 침묵을 짐작했는지도 모른다. 그렇지 않으면 대문에 들어서자마자 전에 없이, “이 난장 맞을 년, 남편이 들어오는데 나와보지도 않아, 이 오라질 년.”이라고 고함을 친 게 수상하다. 이 고함이야말로 제 몸을 엄습해오는 무시무시한 증을 쫓아버리려는 허장성세(虛張聲勢)인 까닭이다.
하여간 김 첨지는 방문을 왈칵 열었다. 구역을 나게 하는 추기 - 떨어진 삿자리 밑에서 나온 먼지내, 빨지 않은 기저귀에서 나는 똥내와 오줌내, 가지각색 때가 케케히 앉은 옷내, 병인의 땀 썩은 내가 섞인 추기가 무딘 김 첨지의 코를 찔렀다.
방안에 들어서며 설렁탕을 한구석에 놓을 사이도 없이 주정군은 목청을 있는 대로 다 내어 호통을 쳤다.
“이런 오라질 년, 주야장천(晝夜長川) 누워만 있으면 제일이야! 남편이 와도 일어나지를 못해.”라는 소리와 함께 발길로 누운 이의 다리를 몹시 찼다. 그러나 발길에 채이는 건 사람의 살이 아니고 나무등걸과 같은 느낌이 있었다. 이때에 빽빽 소리가 응아 소리로 변하였다. 개똥이가 물었던 젖을 빼어놓고 운다. 운대도 온 얼굴을 찡그려 붙여서, 운다는 표정을 할 뿐이다. 응아 소리도 입에서 나는 게 아니고 마치 뱃속에서 나는 듯하였다. 울다가 울다가 목도 잠겼고 또 울 기운조차 시진한 것 같다.
발로 차도 그 보람이 없는 걸 보자 남편은 아내의 머리맡으로 달려들어 그야말로 까치집 같은 환자의 머리를 꺼들어 흔들며, “이 년아, 말을 해, 말을! 입이 붙었어, 이 오라질 년!”
“…”
“으응, 이것 봐, 아무 말이 없네.”
“…”
“이년아, 죽었단 말이냐, 왜 말이 없어.”
“…”
“으응. 또 대답이 없네, 정말 죽었나버이.”
이러다가 누운 이의 흰 창을 덮은, 위로 치뜬 눈을 알아보자마자, “이 눈깔! 이 눈깔! 왜 나를 바라보지 못하고 천정만 보느냐, 응.”하는 말 끝엔 목이 메었다. 그러자 산 사람의 눈에서 떨어진 닭의 똥 같은 눈물이 죽은 이의 뻣뻣한 얼굴을 어룽어룽 적시었다. 문득 김 첨지는 미칠 듯이 제 얼굴을 죽은 이의 얼굴에 한테 비비대며 중얼거렸다.
“설렁탕을 사다놓았는데 왜 먹지를 못하니, 왜 먹지를 못하니... 괴상하게도 오늘은! 운수가 좋더니만... ”

View File

@ -0,0 +1,45 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package traditionalchinese
import (
"testing"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/internal"
"golang.org/x/text/transform"
)
func dec(e encoding.Encoding) (dir string, t transform.Transformer, err error) {
return "Decode", e.NewDecoder(), nil
}
func enc(e encoding.Encoding) (dir string, t transform.Transformer, err error) {
return "Encode", e.NewEncoder(), internal.ErrASCIIReplacement
}
func TestNonRepertoire(t *testing.T) {
testCases := []struct {
init func(e encoding.Encoding) (string, transform.Transformer, error)
e encoding.Encoding
src, want string
}{
{dec, Big5, "\x81\x40", "\ufffd"},
{enc, Big5, "갂", ""},
{enc, Big5, "a갂", "a"},
{enc, Big5, "\u43f0갂", "\x87@"},
}
for _, tc := range testCases {
dir, tr, wantErr := tc.init(tc.e)
dst, _, err := transform.String(tr, tc.src)
if err != wantErr {
t.Errorf("%s %v(%q): got %v; want %v", dir, tc.e, tc.src, err, wantErr)
}
if got := string(dst); got != tc.want {
t.Errorf("%s %v(%q):\ngot %q\nwant %q", dir, tc.e, tc.src, got, tc.want)
}
}
}

View File

@ -0,0 +1,198 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package traditionalchinese
import (
"errors"
"unicode/utf8"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/internal"
"golang.org/x/text/encoding/internal/identifier"
"golang.org/x/text/transform"
)
// All is a list of all defined encodings in this package.
var All = []encoding.Encoding{Big5}
// Big5 is the Big5 encoding, also known as Code Page 950.
var Big5 encoding.Encoding = &big5
var big5 = internal.Encoding{
&internal.SimpleEncoding{big5Decoder{}, big5Encoder{}},
"Big5",
identifier.Big5,
}
var errInvalidBig5 = errors.New("traditionalchinese: invalid Big5 encoding")
type big5Decoder struct{ transform.NopResetter }
func (big5Decoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
r, size, s := rune(0), 0, ""
loop:
for ; nSrc < len(src); nSrc += size {
switch c0 := src[nSrc]; {
case c0 < utf8.RuneSelf:
r, size = rune(c0), 1
case 0x81 <= c0 && c0 < 0xff:
if nSrc+1 >= len(src) {
err = transform.ErrShortSrc
break loop
}
c1 := src[nSrc+1]
switch {
case 0x40 <= c1 && c1 < 0x7f:
c1 -= 0x40
case 0xa1 <= c1 && c1 < 0xff:
c1 -= 0x62
default:
err = errInvalidBig5
break loop
}
r, size = '\ufffd', 2
if i := int(c0-0x81)*157 + int(c1); i < len(decode) {
if 1133 <= i && i < 1167 {
// The two-rune special cases for LATIN CAPITAL / SMALL E WITH CIRCUMFLEX
// AND MACRON / CARON are from http://encoding.spec.whatwg.org/#big5
switch i {
case 1133:
s = "\u00CA\u0304"
goto writeStr
case 1135:
s = "\u00CA\u030C"
goto writeStr
case 1164:
s = "\u00EA\u0304"
goto writeStr
case 1166:
s = "\u00EA\u030C"
goto writeStr
}
}
r = rune(decode[i])
if r == 0 {
r = '\ufffd'
}
}
default:
err = errInvalidBig5
break loop
}
if nDst+utf8.RuneLen(r) > len(dst) {
err = transform.ErrShortDst
break loop
}
nDst += utf8.EncodeRune(dst[nDst:], r)
continue loop
writeStr:
if nDst+len(s) > len(dst) {
err = transform.ErrShortDst
break loop
}
nDst += copy(dst[nDst:], s)
continue loop
}
if atEOF && err == transform.ErrShortSrc {
err = errInvalidBig5
}
return nDst, nSrc, err
}
type big5Encoder struct{ transform.NopResetter }
func (big5Encoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
r, size := rune(0), 0
for ; nSrc < len(src); nSrc += size {
r = rune(src[nSrc])
// Decode a 1-byte rune.
if r < utf8.RuneSelf {
size = 1
if nDst >= len(dst) {
err = transform.ErrShortDst
break
}
dst[nDst] = uint8(r)
nDst++
continue
} else {
// Decode a multi-byte rune.
r, size = utf8.DecodeRune(src[nSrc:])
if size == 1 {
// All valid runes of size 1 (those below utf8.RuneSelf) were
// handled above. We have invalid UTF-8 or we haven't seen the
// full character yet.
if !atEOF && !utf8.FullRune(src[nSrc:]) {
err = transform.ErrShortSrc
break
}
}
}
if r >= utf8.RuneSelf {
// func init checks that the switch covers all tables.
switch {
case encode0Low <= r && r < encode0High:
if r = rune(encode0[r-encode0Low]); r != 0 {
goto write2
}
case encode1Low <= r && r < encode1High:
if r = rune(encode1[r-encode1Low]); r != 0 {
goto write2
}
case encode2Low <= r && r < encode2High:
if r = rune(encode2[r-encode2Low]); r != 0 {
goto write2
}
case encode3Low <= r && r < encode3High:
if r = rune(encode3[r-encode3Low]); r != 0 {
goto write2
}
case encode4Low <= r && r < encode4High:
if r = rune(encode4[r-encode4Low]); r != 0 {
goto write2
}
case encode5Low <= r && r < encode5High:
if r = rune(encode5[r-encode5Low]); r != 0 {
goto write2
}
case encode6Low <= r && r < encode6High:
if r = rune(encode6[r-encode6Low]); r != 0 {
goto write2
}
case encode7Low <= r && r < encode7High:
if r = rune(encode7[r-encode7Low]); r != 0 {
goto write2
}
}
err = internal.ErrASCIIReplacement
break
}
write2:
if nDst+2 > len(dst) {
err = transform.ErrShortDst
break
}
dst[nDst+0] = uint8(r >> 8)
dst[nDst+1] = uint8(r)
nDst += 2
continue
}
return nDst, nSrc, err
}
func init() {
// Check that the hard-coded encode switch covers all tables.
if numEncodeTables != 8 {
panic("bad numEncodeTables")
}
}

View File

@ -0,0 +1,140 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
package main
// This program generates tables.go:
// go run maketables.go | gofmt > tables.go
import (
"bufio"
"fmt"
"log"
"net/http"
"sort"
"strings"
)
func main() {
fmt.Printf("// generated by go run maketables.go; DO NOT EDIT\n\n")
fmt.Printf("// Package traditionalchinese provides Traditional Chinese encodings such as Big5.\n")
fmt.Printf(`package traditionalchinese // import "golang.org/x/text/encoding/traditionalchinese"` + "\n\n")
res, err := http.Get("http://encoding.spec.whatwg.org/index-big5.txt")
if err != nil {
log.Fatalf("Get: %v", err)
}
defer res.Body.Close()
mapping := [65536]uint32{}
reverse := [65536 * 4]uint16{}
scanner := bufio.NewScanner(res.Body)
for scanner.Scan() {
s := strings.TrimSpace(scanner.Text())
if s == "" || s[0] == '#' {
continue
}
x, y := uint16(0), uint32(0)
if _, err := fmt.Sscanf(s, "%d 0x%x", &x, &y); err != nil {
log.Fatalf("could not parse %q", s)
}
if x < 0 || 126*157 <= x {
log.Fatalf("Big5 code %d is out of range", x)
}
mapping[x] = y
// The WHATWG spec http://encoding.spec.whatwg.org/#indexes says that
// "The index pointer for code point in index is the first pointer
// corresponding to code point in index", which would normally mean
// that the code below should be guarded by "if reverse[y] == 0", but
// last instead of first seems to match the behavior of
// "iconv -f UTF-8 -t BIG5". For example, U+8005 者 occurs twice in
// http://encoding.spec.whatwg.org/index-big5.txt, as index 2148
// (encoded as "\x8e\xcd") and index 6543 (encoded as "\xaa\xcc")
// and "echo 者 | iconv -f UTF-8 -t BIG5 | xxd" gives "\xaa\xcc".
c0, c1 := x/157, x%157
if c1 < 0x3f {
c1 += 0x40
} else {
c1 += 0x62
}
reverse[y] = (0x81+c0)<<8 | c1
}
if err := scanner.Err(); err != nil {
log.Fatalf("scanner error: %v", err)
}
fmt.Printf("// decode is the decoding table from Big5 code to Unicode.\n")
fmt.Printf("// It is defined at http://encoding.spec.whatwg.org/index-big5.txt\n")
fmt.Printf("var decode = [...]uint32{\n")
for i, v := range mapping {
if v != 0 {
fmt.Printf("\t%d: 0x%08X,\n", i, v)
}
}
fmt.Printf("}\n\n")
// Any run of at least separation continuous zero entries in the reverse map will
// be a separate encode table.
const separation = 1024
intervals := []interval(nil)
low, high := -1, -1
for i, v := range reverse {
if v == 0 {
continue
}
if low < 0 {
low = i
} else if i-high >= separation {
if high >= 0 {
intervals = append(intervals, interval{low, high})
}
low = i
}
high = i + 1
}
if high >= 0 {
intervals = append(intervals, interval{low, high})
}
sort.Sort(byDecreasingLength(intervals))
fmt.Printf("const numEncodeTables = %d\n\n", len(intervals))
fmt.Printf("// encodeX are the encoding tables from Unicode to Big5 code,\n")
fmt.Printf("// sorted by decreasing length.\n")
for i, v := range intervals {
fmt.Printf("// encode%d: %5d entries for runes in [%6d, %6d).\n", i, v.len(), v.low, v.high)
}
fmt.Printf("\n")
for i, v := range intervals {
fmt.Printf("const encode%dLow, encode%dHigh = %d, %d\n\n", i, i, v.low, v.high)
fmt.Printf("var encode%d = [...]uint16{\n", i)
for j := v.low; j < v.high; j++ {
x := reverse[j]
if x == 0 {
continue
}
fmt.Printf("\t%d-%d: 0x%04X,\n", j, v.low, x)
}
fmt.Printf("}\n\n")
}
}
// interval is a half-open interval [low, high).
type interval struct {
low, high int
}
func (i interval) len() int { return i.high - i.low }
// byDecreasingLength sorts intervals by decreasing length.
type byDecreasingLength []interval
func (b byDecreasingLength) Len() int { return len(b) }
func (b byDecreasingLength) Less(i, j int) bool { return b[i].len() > b[j].len() }
func (b byDecreasingLength) Swap(i, j int) { b[i], b[j] = b[j], b[i] }

File diff suppressed because it is too large Load Diff

82
vendor/golang.org/x/text/encoding/unicode/override.go generated vendored Normal file
View File

@ -0,0 +1,82 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package unicode
import (
"golang.org/x/text/transform"
)
// BOMOverride returns a new decoder transformer that is identical to fallback,
// except that the presence of a Byte Order Mark at the start of the input
// causes it to switch to the corresponding Unicode decoding. It will only
// consider BOMs for UTF-8, UTF-16BE, and UTF-16LE.
//
// This differs from using ExpectBOM by allowing a BOM to switch to UTF-8, not
// just UTF-16 variants, and allowing falling back to any encoding scheme.
//
// This technique is recommended by the W3C for use in HTML 5: "For
// compatibility with deployed content, the byte order mark (also known as BOM)
// is considered more authoritative than anything else."
// http://www.w3.org/TR/encoding/#specification-hooks
//
// Using BOMOverride is mostly intended for use cases where the first characters
// of a fallback encoding are known to not be a BOM, for example, for valid HTML
// and most encodings.
func BOMOverride(fallback transform.Transformer) transform.Transformer {
// TODO: possibly allow a variadic argument of unicode encodings to allow
// specifying details of which fallbacks are supported as well as
// specifying the details of the implementations. This would also allow for
// support for UTF-32, which should not be supported by default.
return &bomOverride{fallback: fallback}
}
type bomOverride struct {
fallback transform.Transformer
current transform.Transformer
}
func (d *bomOverride) Reset() {
d.current = nil
d.fallback.Reset()
}
var (
// TODO: we could use decode functions here, instead of allocating a new
// decoder on every NewDecoder as IgnoreBOM decoders can be stateless.
utf16le = UTF16(LittleEndian, IgnoreBOM)
utf16be = UTF16(BigEndian, IgnoreBOM)
)
const utf8BOM = "\ufeff"
func (d *bomOverride) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
if d.current != nil {
return d.current.Transform(dst, src, atEOF)
}
if len(src) < 3 && !atEOF {
return 0, 0, transform.ErrShortSrc
}
d.current = d.fallback
bomSize := 0
if len(src) >= 2 {
if src[0] == 0xFF && src[1] == 0xFE {
d.current = utf16le.NewDecoder()
bomSize = 2
} else if src[0] == 0xFE && src[1] == 0xFF {
d.current = utf16be.NewDecoder()
bomSize = 2
} else if len(src) >= 3 &&
src[0] == utf8BOM[0] &&
src[1] == utf8BOM[1] &&
src[2] == utf8BOM[2] {
d.current = transform.Nop
bomSize = 3
}
}
if bomSize < len(src) {
nDst, nSrc, err = d.current.Transform(dst, src[bomSize:], atEOF)
}
return nDst, nSrc + bomSize, err
}

434
vendor/golang.org/x/text/encoding/unicode/unicode.go generated vendored Normal file
View File

@ -0,0 +1,434 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package unicode provides Unicode encodings such as UTF-16.
package unicode // import "golang.org/x/text/encoding/unicode"
import (
"errors"
"unicode/utf16"
"unicode/utf8"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/internal"
"golang.org/x/text/encoding/internal/identifier"
"golang.org/x/text/internal/utf8internal"
"golang.org/x/text/runes"
"golang.org/x/text/transform"
)
// TODO: I think the Transformers really should return errors on unmatched
// surrogate pairs and odd numbers of bytes. This is not required by RFC 2781,
// which leaves it open, but is suggested by WhatWG. It will allow for all error
// modes as defined by WhatWG: fatal, HTML and Replacement. This would require
// the introduction of some kind of error type for conveying the erroneous code
// point.
// UTF8 is the UTF-8 encoding.
var UTF8 encoding.Encoding = utf8enc
var utf8enc = &internal.Encoding{
&internal.SimpleEncoding{utf8Decoder{}, runes.ReplaceIllFormed()},
"UTF-8",
identifier.UTF8,
}
type utf8Decoder struct{ transform.NopResetter }
func (utf8Decoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
var pSrc int // point from which to start copy in src
var accept utf8internal.AcceptRange
// The decoder can only make the input larger, not smaller.
n := len(src)
if len(dst) < n {
err = transform.ErrShortDst
n = len(dst)
atEOF = false
}
for nSrc < n {
c := src[nSrc]
if c < utf8.RuneSelf {
nSrc++
continue
}
first := utf8internal.First[c]
size := int(first & utf8internal.SizeMask)
if first == utf8internal.FirstInvalid {
goto handleInvalid // invalid starter byte
}
accept = utf8internal.AcceptRanges[first>>utf8internal.AcceptShift]
if nSrc+size > n {
if !atEOF {
// We may stop earlier than necessary here if the short sequence
// has invalid bytes. Not checking for this simplifies the code
// and may avoid duplicate computations in certain conditions.
if err == nil {
err = transform.ErrShortSrc
}
break
}
// Determine the maximal subpart of an ill-formed subsequence.
switch {
case nSrc+1 >= n || src[nSrc+1] < accept.Lo || accept.Hi < src[nSrc+1]:
size = 1
case nSrc+2 >= n || src[nSrc+2] < utf8internal.LoCB || utf8internal.HiCB < src[nSrc+2]:
size = 2
default:
size = 3 // As we are short, the maximum is 3.
}
goto handleInvalid
}
if c = src[nSrc+1]; c < accept.Lo || accept.Hi < c {
size = 1
goto handleInvalid // invalid continuation byte
} else if size == 2 {
} else if c = src[nSrc+2]; c < utf8internal.LoCB || utf8internal.HiCB < c {
size = 2
goto handleInvalid // invalid continuation byte
} else if size == 3 {
} else if c = src[nSrc+3]; c < utf8internal.LoCB || utf8internal.HiCB < c {
size = 3
goto handleInvalid // invalid continuation byte
}
nSrc += size
continue
handleInvalid:
// Copy the scanned input so far.
nDst += copy(dst[nDst:], src[pSrc:nSrc])
// Append RuneError to the destination.
const runeError = "\ufffd"
if nDst+len(runeError) > len(dst) {
return nDst, nSrc, transform.ErrShortDst
}
nDst += copy(dst[nDst:], runeError)
// Skip the maximal subpart of an ill-formed subsequence according to
// the W3C standard way instead of the Go way. This Transform is
// probably the only place in the text repo where it is warranted.
nSrc += size
pSrc = nSrc
// Recompute the maximum source length.
if sz := len(dst) - nDst; sz < len(src)-nSrc {
err = transform.ErrShortDst
n = nSrc + sz
atEOF = false
}
}
return nDst + copy(dst[nDst:], src[pSrc:nSrc]), nSrc, err
}
// UTF16 returns a UTF-16 Encoding for the given default endianness and byte
// order mark (BOM) policy.
//
// When decoding from UTF-16 to UTF-8, if the BOMPolicy is IgnoreBOM then
// neither BOMs U+FEFF nor noncharacters U+FFFE in the input stream will affect
// the endianness used for decoding, and will instead be output as their
// standard UTF-8 encodings: "\xef\xbb\xbf" and "\xef\xbf\xbe". If the BOMPolicy
// is UseBOM or ExpectBOM a staring BOM is not written to the UTF-8 output.
// Instead, it overrides the default endianness e for the remainder of the
// transformation. Any subsequent BOMs U+FEFF or noncharacters U+FFFE will not
// affect the endianness used, and will instead be output as their standard
// UTF-8 encodings. For UseBOM, if there is no starting BOM, it will proceed
// with the default Endianness. For ExpectBOM, in that case, the transformation
// will return early with an ErrMissingBOM error.
//
// When encoding from UTF-8 to UTF-16, a BOM will be inserted at the start of
// the output if the BOMPolicy is UseBOM or ExpectBOM. Otherwise, a BOM will not
// be inserted. The UTF-8 input does not need to contain a BOM.
//
// There is no concept of a 'native' endianness. If the UTF-16 data is produced
// and consumed in a greater context that implies a certain endianness, use
// IgnoreBOM. Otherwise, use ExpectBOM and always produce and consume a BOM.
//
// In the language of http://www.unicode.org/faq/utf_bom.html#bom10, IgnoreBOM
// corresponds to "Where the precise type of the data stream is known... the
// BOM should not be used" and ExpectBOM corresponds to "A particular
// protocol... may require use of the BOM".
func UTF16(e Endianness, b BOMPolicy) encoding.Encoding {
return utf16Encoding{config{e, b}, mibValue[e][b&bomMask]}
}
// mibValue maps Endianness and BOMPolicy settings to MIB constants. Note that
// some configurations map to the same MIB identifier. RFC 2781 has requirements
// and recommendations. Some of the "configurations" are merely recommendations,
// so multiple configurations could match.
var mibValue = map[Endianness][numBOMValues]identifier.MIB{
BigEndian: [numBOMValues]identifier.MIB{
IgnoreBOM: identifier.UTF16BE,
UseBOM: identifier.UTF16, // BigEnding default is preferred by RFC 2781.
// TODO: acceptBOM | strictBOM would map to UTF16BE as well.
},
LittleEndian: [numBOMValues]identifier.MIB{
IgnoreBOM: identifier.UTF16LE,
UseBOM: identifier.UTF16, // LittleEndian default is allowed and preferred on Windows.
// TODO: acceptBOM | strictBOM would map to UTF16LE as well.
},
// ExpectBOM is not widely used and has no valid MIB identifier.
}
// All lists a configuration for each IANA-defined UTF-16 variant.
var All = []encoding.Encoding{
UTF8,
UTF16(BigEndian, UseBOM),
UTF16(BigEndian, IgnoreBOM),
UTF16(LittleEndian, IgnoreBOM),
}
// BOMPolicy is a UTF-16 encoding's byte order mark policy.
type BOMPolicy uint8
const (
writeBOM BOMPolicy = 0x01
acceptBOM BOMPolicy = 0x02
requireBOM BOMPolicy = 0x04
bomMask BOMPolicy = 0x07
// HACK: numBOMValues == 8 triggers a bug in the 1.4 compiler (cannot have a
// map of an array of length 8 of a type that is also used as a key or value
// in another map). See golang.org/issue/11354.
// TODO: consider changing this value back to 8 if the use of 1.4.* has
// been minimized.
numBOMValues = 8 + 1
// IgnoreBOM means to ignore any byte order marks.
IgnoreBOM BOMPolicy = 0
// Common and RFC 2781-compliant interpretation for UTF-16BE/LE.
// UseBOM means that the UTF-16 form may start with a byte order mark, which
// will be used to override the default encoding.
UseBOM BOMPolicy = writeBOM | acceptBOM
// Common and RFC 2781-compliant interpretation for UTF-16.
// ExpectBOM means that the UTF-16 form must start with a byte order mark,
// which will be used to override the default encoding.
ExpectBOM BOMPolicy = writeBOM | acceptBOM | requireBOM
// Used in Java as Unicode (not to be confused with Java's UTF-16) and
// ICU's UTF-16,version=1. Not compliant with RFC 2781.
// TODO (maybe): strictBOM: BOM must match Endianness. This would allow:
// - UTF-16(B|L)E,version=1: writeBOM | acceptBOM | requireBOM | strictBOM
// (UnicodeBig and UnicodeLittle in Java)
// - RFC 2781-compliant, but less common interpretation for UTF-16(B|L)E:
// acceptBOM | strictBOM (e.g. assigned to CheckBOM).
// This addition would be consistent with supporting ExpectBOM.
)
// Endianness is a UTF-16 encoding's default endianness.
type Endianness bool
const (
// BigEndian is UTF-16BE.
BigEndian Endianness = false
// LittleEndian is UTF-16LE.
LittleEndian Endianness = true
)
// ErrMissingBOM means that decoding UTF-16 input with ExpectBOM did not find a
// starting byte order mark.
var ErrMissingBOM = errors.New("encoding: missing byte order mark")
type utf16Encoding struct {
config
mib identifier.MIB
}
type config struct {
endianness Endianness
bomPolicy BOMPolicy
}
func (u utf16Encoding) NewDecoder() *encoding.Decoder {
return &encoding.Decoder{Transformer: &utf16Decoder{
initial: u.config,
current: u.config,
}}
}
func (u utf16Encoding) NewEncoder() *encoding.Encoder {
return &encoding.Encoder{Transformer: &utf16Encoder{
endianness: u.endianness,
initialBOMPolicy: u.bomPolicy,
currentBOMPolicy: u.bomPolicy,
}}
}
func (u utf16Encoding) ID() (mib identifier.MIB, other string) {
return u.mib, ""
}
func (u utf16Encoding) String() string {
e, b := "B", ""
if u.endianness == LittleEndian {
e = "L"
}
switch u.bomPolicy {
case ExpectBOM:
b = "Expect"
case UseBOM:
b = "Use"
case IgnoreBOM:
b = "Ignore"
}
return "UTF-16" + e + "E (" + b + " BOM)"
}
type utf16Decoder struct {
initial config
current config
}
func (u *utf16Decoder) Reset() {
u.current = u.initial
}
func (u *utf16Decoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
if len(src) == 0 {
if atEOF && u.current.bomPolicy&requireBOM != 0 {
return 0, 0, ErrMissingBOM
}
return 0, 0, nil
}
if u.current.bomPolicy&acceptBOM != 0 {
if len(src) < 2 {
return 0, 0, transform.ErrShortSrc
}
switch {
case src[0] == 0xfe && src[1] == 0xff:
u.current.endianness = BigEndian
nSrc = 2
case src[0] == 0xff && src[1] == 0xfe:
u.current.endianness = LittleEndian
nSrc = 2
default:
if u.current.bomPolicy&requireBOM != 0 {
return 0, 0, ErrMissingBOM
}
}
u.current.bomPolicy = IgnoreBOM
}
var r rune
var dSize, sSize int
for nSrc < len(src) {
if nSrc+1 < len(src) {
x := uint16(src[nSrc+0])<<8 | uint16(src[nSrc+1])
if u.current.endianness == LittleEndian {
x = x>>8 | x<<8
}
r, sSize = rune(x), 2
if utf16.IsSurrogate(r) {
if nSrc+3 < len(src) {
x = uint16(src[nSrc+2])<<8 | uint16(src[nSrc+3])
if u.current.endianness == LittleEndian {
x = x>>8 | x<<8
}
// Save for next iteration if it is not a high surrogate.
if isHighSurrogate(rune(x)) {
r, sSize = utf16.DecodeRune(r, rune(x)), 4
}
} else if !atEOF {
err = transform.ErrShortSrc
break
}
}
if dSize = utf8.RuneLen(r); dSize < 0 {
r, dSize = utf8.RuneError, 3
}
} else if atEOF {
// Single trailing byte.
r, dSize, sSize = utf8.RuneError, 3, 1
} else {
err = transform.ErrShortSrc
break
}
if nDst+dSize > len(dst) {
err = transform.ErrShortDst
break
}
nDst += utf8.EncodeRune(dst[nDst:], r)
nSrc += sSize
}
return nDst, nSrc, err
}
func isHighSurrogate(r rune) bool {
return 0xDC00 <= r && r <= 0xDFFF
}
type utf16Encoder struct {
endianness Endianness
initialBOMPolicy BOMPolicy
currentBOMPolicy BOMPolicy
}
func (u *utf16Encoder) Reset() {
u.currentBOMPolicy = u.initialBOMPolicy
}
func (u *utf16Encoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
if u.currentBOMPolicy&writeBOM != 0 {
if len(dst) < 2 {
return 0, 0, transform.ErrShortDst
}
dst[0], dst[1] = 0xfe, 0xff
u.currentBOMPolicy = IgnoreBOM
nDst = 2
}
r, size := rune(0), 0
for nSrc < len(src) {
r = rune(src[nSrc])
// Decode a 1-byte rune.
if r < utf8.RuneSelf {
size = 1
} else {
// Decode a multi-byte rune.
r, size = utf8.DecodeRune(src[nSrc:])
if size == 1 {
// All valid runes of size 1 (those below utf8.RuneSelf) were
// handled above. We have invalid UTF-8 or we haven't seen the
// full character yet.
if !atEOF && !utf8.FullRune(src[nSrc:]) {
err = transform.ErrShortSrc
break
}
}
}
if r <= 0xffff {
if nDst+2 > len(dst) {
err = transform.ErrShortDst
break
}
dst[nDst+0] = uint8(r >> 8)
dst[nDst+1] = uint8(r)
nDst += 2
} else {
if nDst+4 > len(dst) {
err = transform.ErrShortDst
break
}
r1, r2 := utf16.EncodeRune(r)
dst[nDst+0] = uint8(r1 >> 8)
dst[nDst+1] = uint8(r1)
dst[nDst+2] = uint8(r2 >> 8)
dst[nDst+3] = uint8(r2)
nDst += 4
}
nSrc += size
}
if u.endianness == LittleEndian {
for i := 0; i < nDst; i += 2 {
dst[i], dst[i+1] = dst[i+1], dst[i]
}
}
return nDst, nSrc, err
}

View File

@ -0,0 +1,178 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package unicode
import (
"testing"
"golang.org/x/text/transform"
)
func TestUTF8Decoder(t *testing.T) {
testCases := []struct {
desc string
src string
notEOF bool // the inverse of atEOF
sizeDst int
want string
nSrc int
err error
}{{
desc: "empty string, empty dest buffer",
}, {
desc: "empty string",
sizeDst: 8,
}, {
desc: "empty string, streaming",
notEOF: true,
sizeDst: 8,
}, {
desc: "ascii",
src: "abcde",
sizeDst: 8,
want: "abcde",
nSrc: 5,
}, {
desc: "ascii and error",
src: "ab\x80de",
sizeDst: 7,
want: "ab\ufffdde",
nSrc: 5,
}, {
desc: "valid two-byte sequence",
src: "a\u0300bc",
sizeDst: 7,
want: "a\u0300bc",
nSrc: 5,
}, {
desc: "valid three-byte sequence",
src: "a\u0300中",
sizeDst: 7,
want: "a\u0300中",
nSrc: 6,
}, {
desc: "valid four-byte sequence",
src: "a中\U00016F50",
sizeDst: 8,
want: "a中\U00016F50",
nSrc: 8,
}, {
desc: "short source buffer",
src: "abc\xf0\x90",
notEOF: true,
sizeDst: 10,
want: "abc",
nSrc: 3,
err: transform.ErrShortSrc,
}, {
// We don't check for the maximal subpart of an ill-formed subsequence
// at the end of an open segment.
desc: "complete invalid that looks like short at end",
src: "abc\xf0\x80",
notEOF: true,
sizeDst: 10,
want: "abc", // instead of "abc\ufffd\ufffd",
nSrc: 3,
err: transform.ErrShortSrc,
}, {
desc: "incomplete sequence at end",
src: "a\x80bc\xf0\x90",
sizeDst: 9,
want: "a\ufffdbc\ufffd",
nSrc: 6,
}, {
desc: "invalid second byte",
src: "abc\xf0dddd",
sizeDst: 10,
want: "abc\ufffddddd",
nSrc: 8,
}, {
desc: "invalid second byte at end",
src: "abc\xf0d",
sizeDst: 10,
want: "abc\ufffdd",
nSrc: 5,
}, {
desc: "invalid third byte",
src: "a\u0300bc\xf0\x90dddd",
sizeDst: 12,
want: "a\u0300bc\ufffddddd",
nSrc: 11,
}, {
desc: "invalid third byte at end",
src: "a\u0300bc\xf0\x90d",
sizeDst: 12,
want: "a\u0300bc\ufffdd",
nSrc: 8,
}, {
desc: "invalid fourth byte, tight buffer",
src: "a\u0300bc\xf0\x90\x80d",
sizeDst: 9,
want: "a\u0300bc\ufffdd",
nSrc: 9,
}, {
desc: "invalid fourth byte at end",
src: "a\u0300bc\xf0\x90\x80",
sizeDst: 8,
want: "a\u0300bc\ufffd",
nSrc: 8,
}, {
desc: "invalid fourth byte and short four byte sequence",
src: "a\u0300bc\xf0\x90\x80\xf0\x90\x80",
notEOF: true,
sizeDst: 20,
want: "a\u0300bc\ufffd",
nSrc: 8,
err: transform.ErrShortSrc,
}, {
desc: "valid four-byte sequence overflowing short buffer",
src: "a\u0300bc\xf0\x90\x80\x80",
notEOF: true,
sizeDst: 8,
want: "a\u0300bc",
nSrc: 5,
err: transform.ErrShortDst,
}, {
desc: "invalid fourth byte at end short, but short dst",
src: "a\u0300bc\xf0\x90\x80\xf0\x90\x80",
notEOF: true,
sizeDst: 8,
// More bytes would fit in the buffer, but this seems to require a more
// complicated and slower algorithm.
want: "a\u0300bc", // instead of "a\u0300bc"
nSrc: 5,
err: transform.ErrShortDst,
}, {
desc: "short dst for error",
src: "abc\x80",
notEOF: true,
sizeDst: 5,
want: "abc",
nSrc: 3,
err: transform.ErrShortDst,
}, {
desc: "adjusting short dst buffer",
src: "abc\x80ef",
notEOF: true,
sizeDst: 6,
want: "abc\ufffd",
nSrc: 4,
err: transform.ErrShortDst,
}}
tr := UTF8.NewDecoder()
for i, tc := range testCases {
b := make([]byte, tc.sizeDst)
nDst, nSrc, err := tr.Transform(b, []byte(tc.src), !tc.notEOF)
if err != tc.err {
t.Errorf("%d:%s: error was %v; want %v", i, tc.desc, err, tc.err)
}
if got := string(b[:nDst]); got != tc.want {
t.Errorf("%d:%s: result was %q: want %q", i, tc.desc, got, tc.want)
}
if nSrc != tc.nSrc {
t.Errorf("%d:%s: nSrc was %d; want %d", i, tc.desc, nSrc, tc.nSrc)
}
}
}

View File

@ -0,0 +1,296 @@
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package utf32 provides the UTF-32 Unicode encoding.
//
// Please note that support for UTF-32 is discouraged as it is a rare and
// inefficient encoding, unfit for use as an interchange format. For use
// on the web, the W3C strongly discourages its use
// (https://www.w3.org/TR/html5/document-metadata.html#charset)
// while WHATWG directly prohibits supporting it
// (https://html.spec.whatwg.org/multipage/syntax.html#character-encodings).
package utf32 // import "golang.org/x/text/encoding/unicode/utf32"
import (
"errors"
"unicode/utf8"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/internal/identifier"
"golang.org/x/text/transform"
)
// All lists a configuration for each IANA-defined UTF-32 variant.
var All = []encoding.Encoding{
UTF32(BigEndian, UseBOM),
UTF32(BigEndian, IgnoreBOM),
UTF32(LittleEndian, IgnoreBOM),
}
// ErrMissingBOM means that decoding UTF-32 input with ExpectBOM did not
// find a starting byte order mark.
var ErrMissingBOM = errors.New("encoding: missing byte order mark")
// UTF32 returns a UTF-32 Encoding for the given default endianness and
// byte order mark (BOM) policy.
//
// When decoding from UTF-32 to UTF-8, if the BOMPolicy is IgnoreBOM then
// neither BOMs U+FEFF nor ill-formed code units 0xFFFE0000 in the input
// stream will affect the endianness used for decoding. Instead BOMs will
// be output as their standard UTF-8 encoding "\xef\xbb\xbf" while
// 0xFFFE0000 code units will be output as "\xef\xbf\xbd", the standard
// UTF-8 encoding for the Unicode replacement character. If the BOMPolicy
// is UseBOM or ExpectBOM a starting BOM is not written to the UTF-8
// output. Instead, it overrides the default endianness e for the remainder
// of the transformation. Any subsequent BOMs U+FEFF or ill-formed code
// units 0xFFFE0000 will not affect the endianness used, and will instead
// be output as their standard UTF-8 (replacement) encodings. For UseBOM,
// if there is no starting BOM, it will proceed with the default
// Endianness. For ExpectBOM, in that case, the transformation will return
// early with an ErrMissingBOM error.
//
// When encoding from UTF-8 to UTF-32, a BOM will be inserted at the start
// of the output if the BOMPolicy is UseBOM or ExpectBOM. Otherwise, a BOM
// will not be inserted. The UTF-8 input does not need to contain a BOM.
//
// There is no concept of a 'native' endianness. If the UTF-32 data is
// produced and consumed in a greater context that implies a certain
// endianness, use IgnoreBOM. Otherwise, use ExpectBOM and always produce
// and consume a BOM.
//
// In the language of http://www.unicode.org/faq/utf_bom.html#bom10,
// IgnoreBOM corresponds to "Where the precise type of the data stream is
// known... the BOM should not be used" and ExpectBOM corresponds to "A
// particular protocol... may require use of the BOM".
func UTF32(e Endianness, b BOMPolicy) encoding.Encoding {
return utf32Encoding{config{e, b}, mibValue[e][b&bomMask]}
}
// mibValue maps Endianness and BOMPolicy settings to MIB constants for UTF-32.
// Note that some configurations map to the same MIB identifier.
var mibValue = map[Endianness][numBOMValues]identifier.MIB{
BigEndian: [numBOMValues]identifier.MIB{
IgnoreBOM: identifier.UTF32BE,
UseBOM: identifier.UTF32,
},
LittleEndian: [numBOMValues]identifier.MIB{
IgnoreBOM: identifier.UTF32LE,
UseBOM: identifier.UTF32,
},
// ExpectBOM is not widely used and has no valid MIB identifier.
}
// BOMPolicy is a UTF-32 encodings's byte order mark policy.
type BOMPolicy uint8
const (
writeBOM BOMPolicy = 0x01
acceptBOM BOMPolicy = 0x02
requireBOM BOMPolicy = 0x04
bomMask BOMPolicy = 0x07
// HACK: numBOMValues == 8 triggers a bug in the 1.4 compiler (cannot have a
// map of an array of length 8 of a type that is also used as a key or value
// in another map). See golang.org/issue/11354.
// TODO: consider changing this value back to 8 if the use of 1.4.* has
// been minimized.
numBOMValues = 8 + 1
// IgnoreBOM means to ignore any byte order marks.
IgnoreBOM BOMPolicy = 0
// Unicode-compliant interpretation for UTF-32BE/LE.
// UseBOM means that the UTF-32 form may start with a byte order mark,
// which will be used to override the default encoding.
UseBOM BOMPolicy = writeBOM | acceptBOM
// Unicode-compliant interpretation for UTF-32.
// ExpectBOM means that the UTF-32 form must start with a byte order mark,
// which will be used to override the default encoding.
ExpectBOM BOMPolicy = writeBOM | acceptBOM | requireBOM
// Consistent with BOMPolicy definition in golang.org/x/text/encoding/unicode
)
// Endianness is a UTF-32 encoding's default endianness.
type Endianness bool
const (
// BigEndian is UTF-32BE.
BigEndian Endianness = false
// LittleEndian is UTF-32LE.
LittleEndian Endianness = true
)
type config struct {
endianness Endianness
bomPolicy BOMPolicy
}
type utf32Encoding struct {
config
mib identifier.MIB
}
func (u utf32Encoding) NewDecoder() *encoding.Decoder {
return &encoding.Decoder{Transformer: &utf32Decoder{
initial: u.config,
current: u.config,
}}
}
func (u utf32Encoding) NewEncoder() *encoding.Encoder {
return &encoding.Encoder{Transformer: &utf32Encoder{
endianness: u.endianness,
initialBOMPolicy: u.bomPolicy,
currentBOMPolicy: u.bomPolicy,
}}
}
func (u utf32Encoding) ID() (mib identifier.MIB, other string) {
return u.mib, ""
}
func (u utf32Encoding) String() string {
e, b := "B", ""
if u.endianness == LittleEndian {
e = "L"
}
switch u.bomPolicy {
case ExpectBOM:
b = "Expect"
case UseBOM:
b = "Use"
case IgnoreBOM:
b = "Ignore"
}
return "UTF-32" + e + "E (" + b + " BOM)"
}
type utf32Decoder struct {
initial config
current config
}
func (u *utf32Decoder) Reset() {
u.current = u.initial
}
func (u *utf32Decoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
if len(src) == 0 {
if atEOF && u.current.bomPolicy&requireBOM != 0 {
return 0, 0, ErrMissingBOM
}
return 0, 0, nil
}
if u.current.bomPolicy&acceptBOM != 0 {
if len(src) < 4 {
return 0, 0, transform.ErrShortSrc
}
switch {
case src[0] == 0x00 && src[1] == 0x00 && src[2] == 0xfe && src[3] == 0xff:
u.current.endianness = BigEndian
nSrc = 4
case src[0] == 0xff && src[1] == 0xfe && src[2] == 0x00 && src[3] == 0x00:
u.current.endianness = LittleEndian
nSrc = 4
default:
if u.current.bomPolicy&requireBOM != 0 {
return 0, 0, ErrMissingBOM
}
}
u.current.bomPolicy = IgnoreBOM
}
var r rune
var dSize, sSize int
for nSrc < len(src) {
if nSrc+3 < len(src) {
x := uint32(src[nSrc+0])<<24 | uint32(src[nSrc+1])<<16 |
uint32(src[nSrc+2])<<8 | uint32(src[nSrc+3])
if u.current.endianness == LittleEndian {
x = x>>24 | (x >> 8 & 0x0000FF00) | (x << 8 & 0x00FF0000) | x<<24
}
r, sSize = rune(x), 4
if dSize = utf8.RuneLen(r); dSize < 0 {
r, dSize = utf8.RuneError, 3
}
} else if atEOF {
// 1..3 trailing bytes.
r, dSize, sSize = utf8.RuneError, 3, len(src)-nSrc
} else {
err = transform.ErrShortSrc
break
}
if nDst+dSize > len(dst) {
err = transform.ErrShortDst
break
}
nDst += utf8.EncodeRune(dst[nDst:], r)
nSrc += sSize
}
return nDst, nSrc, err
}
type utf32Encoder struct {
endianness Endianness
initialBOMPolicy BOMPolicy
currentBOMPolicy BOMPolicy
}
func (u *utf32Encoder) Reset() {
u.currentBOMPolicy = u.initialBOMPolicy
}
func (u *utf32Encoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
if u.currentBOMPolicy&writeBOM != 0 {
if len(dst) < 4 {
return 0, 0, transform.ErrShortDst
}
dst[0], dst[1], dst[2], dst[3] = 0x00, 0x00, 0xfe, 0xff
u.currentBOMPolicy = IgnoreBOM
nDst = 4
}
r, size := rune(0), 0
for nSrc < len(src) {
r = rune(src[nSrc])
// Decode a 1-byte rune.
if r < utf8.RuneSelf {
size = 1
} else {
// Decode a multi-byte rune.
r, size = utf8.DecodeRune(src[nSrc:])
if size == 1 {
// All valid runes of size 1 (those below utf8.RuneSelf) were
// handled above. We have invalid UTF-8 or we haven't seen the
// full character yet.
if !atEOF && !utf8.FullRune(src[nSrc:]) {
err = transform.ErrShortSrc
break
}
}
}
if nDst+4 > len(dst) {
err = transform.ErrShortDst
break
}
dst[nDst+0] = uint8(r >> 24)
dst[nDst+1] = uint8(r >> 16)
dst[nDst+2] = uint8(r >> 8)
dst[nDst+3] = uint8(r)
nDst += 4
nSrc += size
}
if u.endianness == LittleEndian {
for i := 0; i < nDst; i += 4 {
dst[i], dst[i+1], dst[i+2], dst[i+3] = dst[i+3], dst[i+2], dst[i+1], dst[i]
}
}
return nDst, nSrc, err
}

View File

@ -0,0 +1,210 @@
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package utf32
import (
"testing"
"golang.org/x/text/transform"
)
var (
utf32LEIB = UTF32(LittleEndian, IgnoreBOM) // UTF-32LE (atypical interpretation)
utf32LEUB = UTF32(LittleEndian, UseBOM) // UTF-32, LE
// utf32LEEB = UTF32(LittleEndian, ExpectBOM) // UTF-32, LE, Expect - covered in encoding_test.go
utf32BEIB = UTF32(BigEndian, IgnoreBOM) // UTF-32BE (atypical interpretation)
utf32BEUB = UTF32(BigEndian, UseBOM) // UTF-32 default
utf32BEEB = UTF32(BigEndian, ExpectBOM) // UTF-32 Expect
)
func TestUTF32(t *testing.T) {
testCases := []struct {
desc string
src string
notEOF bool // the inverse of atEOF
sizeDst int
want string
nSrc int
err error
t transform.Transformer
}{{
desc: "utf-32 IgnoreBOM dec: empty string",
t: utf32BEIB.NewDecoder(),
}, {
desc: "utf-32 UseBOM dec: empty string",
t: utf32BEUB.NewDecoder(),
}, {
desc: "utf-32 ExpectBOM dec: empty string",
err: ErrMissingBOM,
t: utf32BEEB.NewDecoder(),
}, {
desc: "utf-32be dec: Doesn't interpret U+FEFF as BOM",
src: "\x00\x00\xFE\xFF\x00\x01\x23\x45\x00\x00\x00\x3D\x00\x00\x00\x52\x00\x00\x00\x61",
sizeDst: 100,
want: "\uFEFF\U00012345=Ra",
nSrc: 20,
t: utf32BEIB.NewDecoder(),
}, {
desc: "utf-32be dec: Interprets little endian U+FEFF as invalid",
src: "\xFF\xFE\x00\x00\x00\x01\x23\x45\x00\x00\x00\x3D\x00\x00\x00\x52\x00\x00\x00\x61",
sizeDst: 100,
want: "\uFFFD\U00012345=Ra",
nSrc: 20,
t: utf32BEIB.NewDecoder(),
}, {
desc: "utf-32le dec: Doesn't interpret U+FEFF as BOM",
src: "\xFF\xFE\x00\x00\x45\x23\x01\x00\x3D\x00\x00\x00\x52\x00\x00\x00\x61\x00\x00\x00",
sizeDst: 100,
want: "\uFEFF\U00012345=Ra",
nSrc: 20,
t: utf32LEIB.NewDecoder(),
}, {
desc: "utf-32le dec: Interprets big endian U+FEFF as invalid",
src: "\x00\x00\xFE\xFF\x45\x23\x01\x00\x3D\x00\x00\x00\x52\x00\x00\x00\x61\x00\x00\x00",
sizeDst: 100,
want: "\uFFFD\U00012345=Ra",
nSrc: 20,
t: utf32LEIB.NewDecoder(),
}, {
desc: "utf-32 enc: Writes big-endian BOM",
src: "\U00012345=Ra",
sizeDst: 100,
want: "\x00\x00\xFE\xFF\x00\x01\x23\x45\x00\x00\x00\x3D\x00\x00\x00\x52\x00\x00\x00\x61",
nSrc: 7,
t: utf32BEUB.NewEncoder(),
}, {
desc: "utf-32 enc: Writes little-endian BOM",
src: "\U00012345=Ra",
sizeDst: 100,
want: "\xFF\xFE\x00\x00\x45\x23\x01\x00\x3D\x00\x00\x00\x52\x00\x00\x00\x61\x00\x00\x00",
nSrc: 7,
t: utf32LEUB.NewEncoder(),
}, {
desc: "utf-32 dec: Interprets text using big-endian default when BOM not present",
src: "\x00\x01\x23\x45\x00\x00\x00\x3D\x00\x00\x00\x52\x00\x00\x00\x61",
sizeDst: 100,
want: "\U00012345=Ra",
nSrc: 16,
t: utf32BEUB.NewDecoder(),
}, {
desc: "utf-32 dec: Interprets text using little-endian default when BOM not present",
src: "\x45\x23\x01\x00\x3D\x00\x00\x00\x52\x00\x00\x00\x61\x00\x00\x00",
sizeDst: 100,
want: "\U00012345=Ra",
nSrc: 16,
t: utf32LEUB.NewDecoder(),
}, {
desc: "utf-32 dec: BOM determines encoding BE",
src: "\x00\x00\xFE\xFF\x00\x01\x23\x45\x00\x00\x00\x3D\x00\x00\x00\x52\x00\x00\x00\x61",
sizeDst: 100,
want: "\U00012345=Ra",
nSrc: 20,
t: utf32BEUB.NewDecoder(),
}, {
desc: "utf-32 dec: BOM determines encoding LE",
src: "\xFF\xFE\x00\x00\x45\x23\x01\x00\x3D\x00\x00\x00\x52\x00\x00\x00\x61\x00\x00\x00",
sizeDst: 100,
want: "\U00012345=Ra",
nSrc: 20,
t: utf32LEUB.NewDecoder(),
}, {
desc: "utf-32 dec: BOM determines encoding LE, change default",
src: "\xFF\xFE\x00\x00\x45\x23\x01\x00\x3D\x00\x00\x00\x52\x00\x00\x00\x61\x00\x00\x00",
sizeDst: 100,
want: "\U00012345=Ra",
nSrc: 20,
t: utf32BEUB.NewDecoder(),
}, {
desc: "utf-32 dec: BOM determines encoding BE, change default",
src: "\x00\x00\xFE\xFF\x00\x01\x23\x45\x00\x00\x00\x3D\x00\x00\x00\x52\x00\x00\x00\x61",
sizeDst: 100,
want: "\U00012345=Ra",
nSrc: 20,
t: utf32LEUB.NewDecoder(),
}, {
desc: "utf-32 dec: Don't change big-endian byte order mid-stream",
src: "\x00\x01\x23\x45\x00\x00\x00\x3D\xFF\xFE\x00\x00\x00\x00\xFE\xFF\x00\x00\x00\x52\x00\x00\x00\x61",
sizeDst: 100,
want: "\U00012345=\uFFFD\uFEFFRa",
nSrc: 24,
t: utf32BEUB.NewDecoder(),
}, {
desc: "utf-32 dec: Don't change little-endian byte order mid-stream",
src: "\x45\x23\x01\x00\x3D\x00\x00\x00\x00\x00\xFE\xFF\xFF\xFE\x00\x00\x52\x00\x00\x00\x61\x00\x00\x00",
sizeDst: 100,
want: "\U00012345=\uFFFD\uFEFFRa",
nSrc: 24,
t: utf32LEUB.NewDecoder(),
}, {
desc: "utf-32 dec: Fail on missing BOM when required",
src: "\x00\x01\x23\x45\x00\x00\x00\x3D\x00\x00\x00\x52\x00\x00\x00\x61",
sizeDst: 100,
want: "",
nSrc: 0,
err: ErrMissingBOM,
t: utf32BEEB.NewDecoder(),
}, {
desc: "utf-32 enc: Short dst",
src: "\U00012345=Ra",
sizeDst: 15,
want: "\x00\x01\x23\x45\x00\x00\x00\x3D\x00\x00\x00\x52",
nSrc: 6,
err: transform.ErrShortDst,
t: utf32BEIB.NewEncoder(),
}, {
desc: "utf-32 enc: Short src",
src: "\U00012345=Ra\xC2",
notEOF: true,
sizeDst: 100,
want: "\x00\x01\x23\x45\x00\x00\x00\x3D\x00\x00\x00\x52\x00\x00\x00\x61",
nSrc: 7,
err: transform.ErrShortSrc,
t: utf32BEIB.NewEncoder(),
}, {
desc: "utf-32 enc: Invalid input",
src: "\x80\xC1\xC2\x7F\xC2",
sizeDst: 100,
want: "\x00\x00\xFF\xFD\x00\x00\xFF\xFD\x00\x00\xFF\xFD\x00\x00\x00\x7F\x00\x00\xFF\xFD",
nSrc: 5,
t: utf32BEIB.NewEncoder(),
}, {
desc: "utf-32 dec: Short dst",
src: "\x00\x00\x00\x41",
sizeDst: 0,
want: "",
nSrc: 0,
err: transform.ErrShortDst,
t: utf32BEIB.NewDecoder(),
}, {
desc: "utf-32 dec: Short src",
src: "\x00\x00\x00",
notEOF: true,
sizeDst: 4,
want: "",
nSrc: 0,
err: transform.ErrShortSrc,
t: utf32BEIB.NewDecoder(),
}, {
desc: "utf-32 dec: Invalid input",
src: "\x00\x00\xD8\x00\x00\x00\xDF\xFF\x00\x11\x00\x00\x00\x00\x00",
sizeDst: 100,
want: "\uFFFD\uFFFD\uFFFD\uFFFD",
nSrc: 15,
t: utf32BEIB.NewDecoder(),
}}
for i, tc := range testCases {
b := make([]byte, tc.sizeDst)
nDst, nSrc, err := tc.t.Transform(b, []byte(tc.src), !tc.notEOF)
if err != tc.err {
t.Errorf("%d:%s: error was %v; want %v", i, tc.desc, err, tc.err)
}
if got := string(b[:nDst]); got != tc.want {
t.Errorf("%d:%s: result was %q: want %q", i, tc.desc, got, tc.want)
}
if nSrc != tc.nSrc {
t.Errorf("%d:%s: nSrc was %d; want %d", i, tc.desc, nSrc, tc.nSrc)
}
}
}

37
vendor/golang.org/x/text/transform/examples_test.go generated vendored Normal file
View File

@ -0,0 +1,37 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package transform_test
import (
"fmt"
"unicode"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
)
func ExampleRemoveFunc() {
input := []byte(`tschüß; до свидания`)
b := make([]byte, len(input))
t := transform.RemoveFunc(unicode.IsSpace)
n, _, _ := t.Transform(b, input, true)
fmt.Println(string(b[:n]))
t = transform.RemoveFunc(func(r rune) bool {
return !unicode.Is(unicode.Latin, r)
})
n, _, _ = t.Transform(b, input, true)
fmt.Println(string(b[:n]))
n, _, _ = t.Transform(b, norm.NFD.Bytes(input), true)
fmt.Println(string(b[:n]))
// Output:
// tschüß;досвидания
// tschüß
// tschuß
}

661
vendor/golang.org/x/text/transform/transform.go generated vendored Normal file
View File

@ -0,0 +1,661 @@
// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package transform provides reader and writer wrappers that transform the
// bytes passing through as well as various transformations. Example
// transformations provided by other packages include normalization and
// conversion between character sets.
package transform // import "golang.org/x/text/transform"
import (
"bytes"
"errors"
"io"
"unicode/utf8"
)
var (
// ErrShortDst means that the destination buffer was too short to
// receive all of the transformed bytes.
ErrShortDst = errors.New("transform: short destination buffer")
// ErrShortSrc means that the source buffer has insufficient data to
// complete the transformation.
ErrShortSrc = errors.New("transform: short source buffer")
// errInconsistentByteCount means that Transform returned success (nil
// error) but also returned nSrc inconsistent with the src argument.
errInconsistentByteCount = errors.New("transform: inconsistent byte count returned")
// errShortInternal means that an internal buffer is not large enough
// to make progress and the Transform operation must be aborted.
errShortInternal = errors.New("transform: short internal buffer")
)
// Transformer transforms bytes.
type Transformer interface {
// Transform writes to dst the transformed bytes read from src, and
// returns the number of dst bytes written and src bytes read. The
// atEOF argument tells whether src represents the last bytes of the
// input.
//
// Callers should always process the nDst bytes produced and account
// for the nSrc bytes consumed before considering the error err.
//
// A nil error means that all of the transformed bytes (whether freshly
// transformed from src or left over from previous Transform calls)
// were written to dst. A nil error can be returned regardless of
// whether atEOF is true. If err is nil then nSrc must equal len(src);
// the converse is not necessarily true.
//
// ErrShortDst means that dst was too short to receive all of the
// transformed bytes. ErrShortSrc means that src had insufficient data
// to complete the transformation. If both conditions apply, then
// either error may be returned. Other than the error conditions listed
// here, implementations are free to report other errors that arise.
Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error)
// Reset resets the state and allows a Transformer to be reused.
Reset()
}
// NopResetter can be embedded by implementations of Transformer to add a nop
// Reset method.
type NopResetter struct{}
// Reset implements the Reset method of the Transformer interface.
func (NopResetter) Reset() {}
// Reader wraps another io.Reader by transforming the bytes read.
type Reader struct {
r io.Reader
t Transformer
err error
// dst[dst0:dst1] contains bytes that have been transformed by t but
// not yet copied out via Read.
dst []byte
dst0, dst1 int
// src[src0:src1] contains bytes that have been read from r but not
// yet transformed through t.
src []byte
src0, src1 int
// transformComplete is whether the transformation is complete,
// regardless of whether or not it was successful.
transformComplete bool
}
const defaultBufSize = 4096
// NewReader returns a new Reader that wraps r by transforming the bytes read
// via t. It calls Reset on t.
func NewReader(r io.Reader, t Transformer) *Reader {
t.Reset()
return &Reader{
r: r,
t: t,
dst: make([]byte, defaultBufSize),
src: make([]byte, defaultBufSize),
}
}
// Read implements the io.Reader interface.
func (r *Reader) Read(p []byte) (int, error) {
n, err := 0, error(nil)
for {
// Copy out any transformed bytes and return the final error if we are done.
if r.dst0 != r.dst1 {
n = copy(p, r.dst[r.dst0:r.dst1])
r.dst0 += n
if r.dst0 == r.dst1 && r.transformComplete {
return n, r.err
}
return n, nil
} else if r.transformComplete {
return 0, r.err
}
// Try to transform some source bytes, or to flush the transformer if we
// are out of source bytes. We do this even if r.r.Read returned an error.
// As the io.Reader documentation says, "process the n > 0 bytes returned
// before considering the error".
if r.src0 != r.src1 || r.err != nil {
r.dst0 = 0
r.dst1, n, err = r.t.Transform(r.dst, r.src[r.src0:r.src1], r.err == io.EOF)
r.src0 += n
switch {
case err == nil:
if r.src0 != r.src1 {
r.err = errInconsistentByteCount
}
// The Transform call was successful; we are complete if we
// cannot read more bytes into src.
r.transformComplete = r.err != nil
continue
case err == ErrShortDst && (r.dst1 != 0 || n != 0):
// Make room in dst by copying out, and try again.
continue
case err == ErrShortSrc && r.src1-r.src0 != len(r.src) && r.err == nil:
// Read more bytes into src via the code below, and try again.
default:
r.transformComplete = true
// The reader error (r.err) takes precedence over the
// transformer error (err) unless r.err is nil or io.EOF.
if r.err == nil || r.err == io.EOF {
r.err = err
}
continue
}
}
// Move any untransformed source bytes to the start of the buffer
// and read more bytes.
if r.src0 != 0 {
r.src0, r.src1 = 0, copy(r.src, r.src[r.src0:r.src1])
}
n, r.err = r.r.Read(r.src[r.src1:])
r.src1 += n
}
}
// TODO: implement ReadByte (and ReadRune??).
// Writer wraps another io.Writer by transforming the bytes read.
// The user needs to call Close to flush unwritten bytes that may
// be buffered.
type Writer struct {
w io.Writer
t Transformer
dst []byte
// src[:n] contains bytes that have not yet passed through t.
src []byte
n int
}
// NewWriter returns a new Writer that wraps w by transforming the bytes written
// via t. It calls Reset on t.
func NewWriter(w io.Writer, t Transformer) *Writer {
t.Reset()
return &Writer{
w: w,
t: t,
dst: make([]byte, defaultBufSize),
src: make([]byte, defaultBufSize),
}
}
// Write implements the io.Writer interface. If there are not enough
// bytes available to complete a Transform, the bytes will be buffered
// for the next write. Call Close to convert the remaining bytes.
func (w *Writer) Write(data []byte) (n int, err error) {
src := data
if w.n > 0 {
// Append bytes from data to the last remainder.
// TODO: limit the amount copied on first try.
n = copy(w.src[w.n:], data)
w.n += n
src = w.src[:w.n]
}
for {
nDst, nSrc, err := w.t.Transform(w.dst, src, false)
if _, werr := w.w.Write(w.dst[:nDst]); werr != nil {
return n, werr
}
src = src[nSrc:]
if w.n == 0 {
n += nSrc
} else if len(src) <= n {
// Enough bytes from w.src have been consumed. We make src point
// to data instead to reduce the copying.
w.n = 0
n -= len(src)
src = data[n:]
if n < len(data) && (err == nil || err == ErrShortSrc) {
continue
}
}
switch err {
case ErrShortDst:
// This error is okay as long as we are making progress.
if nDst > 0 || nSrc > 0 {
continue
}
case ErrShortSrc:
if len(src) < len(w.src) {
m := copy(w.src, src)
// If w.n > 0, bytes from data were already copied to w.src and n
// was already set to the number of bytes consumed.
if w.n == 0 {
n += m
}
w.n = m
err = nil
} else if nDst > 0 || nSrc > 0 {
// Not enough buffer to store the remainder. Keep processing as
// long as there is progress. Without this case, transforms that
// require a lookahead larger than the buffer may result in an
// error. This is not something one may expect to be common in
// practice, but it may occur when buffers are set to small
// sizes during testing.
continue
}
case nil:
if w.n > 0 {
err = errInconsistentByteCount
}
}
return n, err
}
}
// Close implements the io.Closer interface.
func (w *Writer) Close() error {
src := w.src[:w.n]
for {
nDst, nSrc, err := w.t.Transform(w.dst, src, true)
if _, werr := w.w.Write(w.dst[:nDst]); werr != nil {
return werr
}
if err != ErrShortDst {
return err
}
src = src[nSrc:]
}
}
type nop struct{ NopResetter }
func (nop) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
n := copy(dst, src)
if n < len(src) {
err = ErrShortDst
}
return n, n, err
}
type discard struct{ NopResetter }
func (discard) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
return 0, len(src), nil
}
var (
// Discard is a Transformer for which all Transform calls succeed
// by consuming all bytes and writing nothing.
Discard Transformer = discard{}
// Nop is a Transformer that copies src to dst.
Nop Transformer = nop{}
)
// chain is a sequence of links. A chain with N Transformers has N+1 links and
// N+1 buffers. Of those N+1 buffers, the first and last are the src and dst
// buffers given to chain.Transform and the middle N-1 buffers are intermediate
// buffers owned by the chain. The i'th link transforms bytes from the i'th
// buffer chain.link[i].b at read offset chain.link[i].p to the i+1'th buffer
// chain.link[i+1].b at write offset chain.link[i+1].n, for i in [0, N).
type chain struct {
link []link
err error
// errStart is the index at which the error occurred plus 1. Processing
// errStart at this level at the next call to Transform. As long as
// errStart > 0, chain will not consume any more source bytes.
errStart int
}
func (c *chain) fatalError(errIndex int, err error) {
if i := errIndex + 1; i > c.errStart {
c.errStart = i
c.err = err
}
}
type link struct {
t Transformer
// b[p:n] holds the bytes to be transformed by t.
b []byte
p int
n int
}
func (l *link) src() []byte {
return l.b[l.p:l.n]
}
func (l *link) dst() []byte {
return l.b[l.n:]
}
// Chain returns a Transformer that applies t in sequence.
func Chain(t ...Transformer) Transformer {
if len(t) == 0 {
return nop{}
}
c := &chain{link: make([]link, len(t)+1)}
for i, tt := range t {
c.link[i].t = tt
}
// Allocate intermediate buffers.
b := make([][defaultBufSize]byte, len(t)-1)
for i := range b {
c.link[i+1].b = b[i][:]
}
return c
}
// Reset resets the state of Chain. It calls Reset on all the Transformers.
func (c *chain) Reset() {
for i, l := range c.link {
if l.t != nil {
l.t.Reset()
}
c.link[i].p, c.link[i].n = 0, 0
}
}
// Transform applies the transformers of c in sequence.
func (c *chain) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
// Set up src and dst in the chain.
srcL := &c.link[0]
dstL := &c.link[len(c.link)-1]
srcL.b, srcL.p, srcL.n = src, 0, len(src)
dstL.b, dstL.n = dst, 0
var lastFull, needProgress bool // for detecting progress
// i is the index of the next Transformer to apply, for i in [low, high].
// low is the lowest index for which c.link[low] may still produce bytes.
// high is the highest index for which c.link[high] has a Transformer.
// The error returned by Transform determines whether to increase or
// decrease i. We try to completely fill a buffer before converting it.
for low, i, high := c.errStart, c.errStart, len(c.link)-2; low <= i && i <= high; {
in, out := &c.link[i], &c.link[i+1]
nDst, nSrc, err0 := in.t.Transform(out.dst(), in.src(), atEOF && low == i)
out.n += nDst
in.p += nSrc
if i > 0 && in.p == in.n {
in.p, in.n = 0, 0
}
needProgress, lastFull = lastFull, false
switch err0 {
case ErrShortDst:
// Process the destination buffer next. Return if we are already
// at the high index.
if i == high {
return dstL.n, srcL.p, ErrShortDst
}
if out.n != 0 {
i++
// If the Transformer at the next index is not able to process any
// source bytes there is nothing that can be done to make progress
// and the bytes will remain unprocessed. lastFull is used to
// detect this and break out of the loop with a fatal error.
lastFull = true
continue
}
// The destination buffer was too small, but is completely empty.
// Return a fatal error as this transformation can never complete.
c.fatalError(i, errShortInternal)
case ErrShortSrc:
if i == 0 {
// Save ErrShortSrc in err. All other errors take precedence.
err = ErrShortSrc
break
}
// Source bytes were depleted before filling up the destination buffer.
// Verify we made some progress, move the remaining bytes to the errStart
// and try to get more source bytes.
if needProgress && nSrc == 0 || in.n-in.p == len(in.b) {
// There were not enough source bytes to proceed while the source
// buffer cannot hold any more bytes. Return a fatal error as this
// transformation can never complete.
c.fatalError(i, errShortInternal)
break
}
// in.b is an internal buffer and we can make progress.
in.p, in.n = 0, copy(in.b, in.src())
fallthrough
case nil:
// if i == low, we have depleted the bytes at index i or any lower levels.
// In that case we increase low and i. In all other cases we decrease i to
// fetch more bytes before proceeding to the next index.
if i > low {
i--
continue
}
default:
c.fatalError(i, err0)
}
// Exhausted level low or fatal error: increase low and continue
// to process the bytes accepted so far.
i++
low = i
}
// If c.errStart > 0, this means we found a fatal error. We will clear
// all upstream buffers. At this point, no more progress can be made
// downstream, as Transform would have bailed while handling ErrShortDst.
if c.errStart > 0 {
for i := 1; i < c.errStart; i++ {
c.link[i].p, c.link[i].n = 0, 0
}
err, c.errStart, c.err = c.err, 0, nil
}
return dstL.n, srcL.p, err
}
// RemoveFunc returns a Transformer that removes from the input all runes r for
// which f(r) is true. Illegal bytes in the input are replaced by RuneError.
func RemoveFunc(f func(r rune) bool) Transformer {
return removeF(f)
}
type removeF func(r rune) bool
func (removeF) Reset() {}
// Transform implements the Transformer interface.
func (t removeF) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
for r, sz := rune(0), 0; len(src) > 0; src = src[sz:] {
if r = rune(src[0]); r < utf8.RuneSelf {
sz = 1
} else {
r, sz = utf8.DecodeRune(src)
if sz == 1 {
// Invalid rune.
if !atEOF && !utf8.FullRune(src) {
err = ErrShortSrc
break
}
// We replace illegal bytes with RuneError. Not doing so might
// otherwise turn a sequence of invalid UTF-8 into valid UTF-8.
// The resulting byte sequence may subsequently contain runes
// for which t(r) is true that were passed unnoticed.
if !t(r) {
if nDst+3 > len(dst) {
err = ErrShortDst
break
}
nDst += copy(dst[nDst:], "\uFFFD")
}
nSrc++
continue
}
}
if !t(r) {
if nDst+sz > len(dst) {
err = ErrShortDst
break
}
nDst += copy(dst[nDst:], src[:sz])
}
nSrc += sz
}
return
}
// grow returns a new []byte that is longer than b, and copies the first n bytes
// of b to the start of the new slice.
func grow(b []byte, n int) []byte {
m := len(b)
if m <= 32 {
m = 64
} else if m <= 256 {
m *= 2
} else {
m += m >> 1
}
buf := make([]byte, m)
copy(buf, b[:n])
return buf
}
const initialBufSize = 128
// String returns a string with the result of converting s[:n] using t, where
// n <= len(s). If err == nil, n will be len(s). It calls Reset on t.
func String(t Transformer, s string) (result string, n int, err error) {
t.Reset()
if s == "" {
// Fast path for the common case for empty input. Results in about a
// 86% reduction of running time for BenchmarkStringLowerEmpty.
if _, _, err := t.Transform(nil, nil, true); err == nil {
return "", 0, nil
}
}
// Allocate only once. Note that both dst and src escape when passed to
// Transform.
buf := [2 * initialBufSize]byte{}
dst := buf[:initialBufSize:initialBufSize]
src := buf[initialBufSize : 2*initialBufSize]
// The input string s is transformed in multiple chunks (starting with a
// chunk size of initialBufSize). nDst and nSrc are per-chunk (or
// per-Transform-call) indexes, pDst and pSrc are overall indexes.
nDst, nSrc := 0, 0
pDst, pSrc := 0, 0
// pPrefix is the length of a common prefix: the first pPrefix bytes of the
// result will equal the first pPrefix bytes of s. It is not guaranteed to
// be the largest such value, but if pPrefix, len(result) and len(s) are
// all equal after the final transform (i.e. calling Transform with atEOF
// being true returned nil error) then we don't need to allocate a new
// result string.
pPrefix := 0
for {
// Invariant: pDst == pPrefix && pSrc == pPrefix.
n := copy(src, s[pSrc:])
nDst, nSrc, err = t.Transform(dst, src[:n], pSrc+n == len(s))
pDst += nDst
pSrc += nSrc
// TODO: let transformers implement an optional Spanner interface, akin
// to norm's QuickSpan. This would even allow us to avoid any allocation.
if !bytes.Equal(dst[:nDst], src[:nSrc]) {
break
}
pPrefix = pSrc
if err == ErrShortDst {
// A buffer can only be short if a transformer modifies its input.
break
} else if err == ErrShortSrc {
if nSrc == 0 {
// No progress was made.
break
}
// Equal so far and !atEOF, so continue checking.
} else if err != nil || pPrefix == len(s) {
return string(s[:pPrefix]), pPrefix, err
}
}
// Post-condition: pDst == pPrefix + nDst && pSrc == pPrefix + nSrc.
// We have transformed the first pSrc bytes of the input s to become pDst
// transformed bytes. Those transformed bytes are discontiguous: the first
// pPrefix of them equal s[:pPrefix] and the last nDst of them equal
// dst[:nDst]. We copy them around, into a new dst buffer if necessary, so
// that they become one contiguous slice: dst[:pDst].
if pPrefix != 0 {
newDst := dst
if pDst > len(newDst) {
newDst = make([]byte, len(s)+nDst-nSrc)
}
copy(newDst[pPrefix:pDst], dst[:nDst])
copy(newDst[:pPrefix], s[:pPrefix])
dst = newDst
}
// Prevent duplicate Transform calls with atEOF being true at the end of
// the input. Also return if we have an unrecoverable error.
if (err == nil && pSrc == len(s)) ||
(err != nil && err != ErrShortDst && err != ErrShortSrc) {
return string(dst[:pDst]), pSrc, err
}
// Transform the remaining input, growing dst and src buffers as necessary.
for {
n := copy(src, s[pSrc:])
nDst, nSrc, err := t.Transform(dst[pDst:], src[:n], pSrc+n == len(s))
pDst += nDst
pSrc += nSrc
// If we got ErrShortDst or ErrShortSrc, do not grow as long as we can
// make progress. This may avoid excessive allocations.
if err == ErrShortDst {
if nDst == 0 {
dst = grow(dst, pDst)
}
} else if err == ErrShortSrc {
if nSrc == 0 {
src = grow(src, 0)
}
} else if err != nil || pSrc == len(s) {
return string(dst[:pDst]), pSrc, err
}
}
}
// Bytes returns a new byte slice with the result of converting b[:n] using t,
// where n <= len(b). If err == nil, n will be len(b). It calls Reset on t.
func Bytes(t Transformer, b []byte) (result []byte, n int, err error) {
return doAppend(t, 0, make([]byte, len(b)), b)
}
// Append appends the result of converting src[:n] using t to dst, where
// n <= len(src), If err == nil, n will be len(src). It calls Reset on t.
func Append(t Transformer, dst, src []byte) (result []byte, n int, err error) {
if len(dst) == cap(dst) {
n := len(src) + len(dst) // It is okay for this to be 0.
b := make([]byte, n)
dst = b[:copy(b, dst)]
}
return doAppend(t, len(dst), dst[:cap(dst)], src)
}
func doAppend(t Transformer, pDst int, dst, src []byte) (result []byte, n int, err error) {
t.Reset()
pSrc := 0
for {
nDst, nSrc, err := t.Transform(dst[pDst:], src[pSrc:], true)
pDst += nDst
pSrc += nSrc
if err != ErrShortDst {
return dst[:pDst], pSrc, err
}
// Grow the destination buffer, but do not grow as long as we can make
// progress. This may avoid excessive allocations.
if nDst == 0 {
dst = grow(dst, pDst)
}
}
}

1317
vendor/golang.org/x/text/transform/transform_test.go generated vendored Normal file

File diff suppressed because it is too large Load Diff