documentation pass done, ready to use the HTML Checker in other code

This commit is contained in:
2025-11-03 15:20:41 -07:00
parent 4f9cdde1f2
commit 1ba02f37e9
7 changed files with 255 additions and 132 deletions
+7
View File
@@ -43,6 +43,7 @@ func (stk *Stack[T]) Peek() (T, bool) {
return stk.elements[len(stk.elements)-1], true
}
// RemoveMostRecent looks for the most recent particular data element on the stack, and removes that.
func (stk *Stack[T]) RemoveMostRecent(data T) bool {
i := len(stk.elements) - 1
for i >= 0 {
@@ -58,10 +59,16 @@ func (stk *Stack[T]) RemoveMostRecent(data T) bool {
}
return true
}
i--
}
return false
}
// Clear clears out the stack.
func (stk *Stack[T]) Clear() {
stk.elements = make([]T, 0)
}
// NewStack creates and returns a new stack.
func NewStack[T comparable]() *Stack[T] {
return &Stack[T]{
+17
View File
@@ -94,10 +94,18 @@ func RunesToBytes(s string, runeCount int) int {
return bp
}
// IsRuneWord returns true if the given rune is part of a word.
func IsRuneWord(ch rune) bool {
return unicode.IsLetter(ch) || ch == '-' || ch == '\''
}
/* WordRunLength calculates the number of runes at the start of the string that are either word or non-word characters.
* Parameters:
* s - The string under test.
* Returns:
* The run length in runes.
* true if the run is a length of word characters, false if it's a run of non-word characters.
*/
func WordRunLength(s string) (int, bool) {
c1, initLen := utf8.DecodeRuneInString(s)
wordChar := IsRuneWord(c1)
@@ -111,6 +119,15 @@ func WordRunLength(s string) (int, bool) {
return rlen, wordChar
}
/* WordRunLengthAfterPrefix calculates the number of runes after a certain number in the string
* that are either word or non-word characters.
* Parameters:
* s - The string under test.
* nrunes - The number of runes to skip at the start of the string.
* Returns:
* The run length in runes.
* true if the run is a length of word characters, false if it's a run of non-word characters.
*/
func WordRunLengthAfterPrefix(s string, nrunes int) (int, bool) {
ofs := 0
for _, ch := range s {