package main

import (
	"fmt"
	"unicode/utf8"
)

func main() {
	// Teks ASCII: satu karakter menempati tepat satu byte.
	fmt.Printf("\"Halo\"  : %d byte, %d rune\n", len("Halo"), utf8.RuneCountInString("Halo"))

	// Huruf beraksen memakai 2 byte dalam UTF-8.
	fmt.Printf("\"café\"  : %d byte, %d rune\n", len("café"), utf8.RuneCountInString("café"))

	// Kanji memakai 3 byte per karakter.
	fmt.Printf("\"日本語\": %d byte, %d rune\n", len("日本語"), utf8.RuneCountInString("日本語"))

	// range menghasilkan indeks byte dan rune, bukan nomor karakter.
	for i, r := range "日本語" {
		fmt.Printf("rune %q mulai di byte %d\n", r, i)
	}

	// DecodeRuneInString mengurai satu rune dari depan string.
	r, lebar := utf8.DecodeRuneInString("日本語")
	fmt.Printf("rune pertama %q lebar %d byte\n", r, lebar)

	// rune adalah alias int32 yang menyimpan code point.
	var kode rune = 'é'
	fmt.Printf("rune %q = code point U+%04X\n", kode, kode)

	// Normalisasi: é composed (1 rune) vs decomposed (2 rune).
	composed := "café"
	decomposed := "cafe\u0301"
	fmt.Printf("composed  : %d byte, %d rune\n", len(composed), utf8.RuneCountInString(composed))
	fmt.Printf("decomposed: %d byte, %d rune\n", len(decomposed), utf8.RuneCountInString(decomposed))
	fmt.Println("tampilan :", composed, "|", decomposed)
	fmt.Println("sama?    :", composed == decomposed)
}
