...

Source file src/oss.terrastruct.com/d2/d2parser/utf16_gen.go

Documentation: oss.terrastruct.com/d2/d2parser

     1  //go:build ignore
     2  
     3  // utf16_gen.go is used to create test UTF-16 input for the UTF-16 input test in parse_test.go
     4  // Confirm `file utf16.txt` returns
     5  package main
     6  
     7  import (
     8  	"bytes"
     9  	"fmt"
    10  	"io"
    11  	"log"
    12  	"os"
    13  	"unicode/utf8"
    14  
    15  	"golang.org/x/text/encoding/unicode"
    16  	"golang.org/x/text/transform"
    17  )
    18  
    19  func main() {
    20  	// Pretend we're on Windows.
    21  	s := "x -> y\r\n"
    22  
    23  	b := &bytes.Buffer{}
    24  	t := transform.NewWriter(b, unicode.UTF16(unicode.LittleEndian, unicode.UseBOM).NewEncoder())
    25  	_, err := io.WriteString(t, s)
    26  	if err != nil {
    27  		log.Fatal(err)
    28  	}
    29  
    30  	fmt.Printf("%q\n", b.String())
    31  	fmt.Println("\xFF\xFE")
    32  	fmt.Println(utf8.ValidString("\xFF\xFE"))
    33  
    34  	err = os.WriteFile("./utf16.d2", b.Bytes(), 0644)
    35  	if err != nil {
    36  		log.Fatal(err)
    37  	}
    38  }
    39  

View as plain text