File: util.go

package info (click to toggle)
golang-github-johanneskaufmann-html-to-markdown 2.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,080 kB
  • sloc: makefile: 3
file content (70 lines) | stat: -rw-r--r-- 1,204 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package escape

import "unicode/utf8"

// TODO: move to markers package?

func IsSpace(b byte) bool {
	switch b {
	case '\t', '\n', '\v', '\f', '\r', ' ', 0x85, 0xA0:
		return true
	}
	return false
}

func IsDigit(b byte) bool {
	switch b {
	case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
		return true
	}
	return false
}

func getPrev(chars []byte, index int) byte {
	for i := index - 1; i >= 0; i-- {
		if chars[i] == placeholderByte {
			continue
		}
		return chars[i]
	}
	return 0
}

func getNext(chars []byte, index int) byte {
	for i := index + 1; i < len(chars); i++ {
		if chars[i] == placeholderByte {
			continue
		}
		return chars[i]
	}
	return 0
}

func getPrevAsRune(chars []byte, index int) rune {
	for i := index - 1; i >= 0; i-- {
		if chars[i] == placeholderByte {
			continue
		}

		r, _ := utf8.DecodeLastRune(chars[:i+1])

		return r
	}
	return 0
}
func getNextAsRune(source []byte, index int) rune {
	for i := index + 1; i < len(source); i++ {
		if source[i] == placeholderByte {
			continue
		}

		r, _ := utf8.DecodeRune(source[i:])
		return r
	}
	return 0
}

// TODO: make public?
func GetNextAsRune(source []byte, index int) rune {
	return getNextAsRune(source, index)
}