aboutsummaryrefslogtreecommitdiff
path: root/lib/bytes/parser_example_test.go
AgeCommit message (Collapse)Author
2025-04-18lib/bytes: add method Peek to ParserShulhan
The Peek method take a look on n bytes inside the buffer without using delimiters. The returned bytes may empty or have length less than n.
2025-04-18lib/bytes: complete the SkipLine example until the endShulhan
This is to see the return value when no token can be parsed and to make the test coverage become 100%.
2024-03-02all: move the repository to "git.sr.ht/~shulhan/pakakeh.go"Shulhan
There are several reasons that why we move from github.com. First, related to the name of package. We accidentally name the package with "share" a common word in English that does not reflect the content of repository. By moving to other repository, we can rename it to better and unique name, in this "pakakeh.go". Pakakeh is Minang word for tools, and ".go" suffix indicate that the repository related to Go programming language. Second, supporting open source. The new repository is hosted under sourcehut.org, the founder is known to support open source, and all their services are licensed under AGPL, unlike GitHub that are closed sources. Third, regarding GitHub CoPilot. The GitHub Terms of Service [1], allow any public content that are hosted there granted them to parse the content. On one side, GitHub helps and flourish the open source, but on another side have an issues regarding scraping the copyleft license [2]. [1]: https://docs.github.com/en/site-policy/github-terms/github-terms-of-service#4-license-grant-to-us [2]: https://githubcopilotinvestigation.com
2023-06-04lib/bytes: use %q to print characters in example codeShulhan
The %q will print the character itself if its printable or an hexadecimal representation.
2023-04-13lib/bytes: move unit Test for Read and SkipLine to ExampleShulhan
Using an example not only test the code but also provide example snippet when opened in the godoc.
2023-04-09lib/bytes: add method ReadLine to ParserShulhan
The ReadLine method read until it found new line ('\n') or end of content, ignoring all delimiters. The returned line will not contain '\n'.
2023-04-09lib/bytes: return the number of skipped chars on Skip(Horizontal)SpacesShulhan
2023-04-09lib/bytes: add method Remaining to ParserShulhan
The Remaining method return the copy of un-parsed content.
2023-04-08lib/bytes: add various methods to ParserShulhan
The AddDelimiters method add another delimiters to the current parser. The ReadNoSpace method read the next token by ignoring the leading spaces, even if its one of the delimiter. The returned token will have no trailing spaces. The RemoveDelimiters method remove delimiters delims from current delimiters. The Reset method set all internal state to new content and delimiters. The SetDelimiters method replace the current delimiters with delims. The SkipHorizontalSpaces method skip space (" "), tab ("\t"), carriage return ("\r"), and form feed ("\f") characters; and return the first non-space character or 0 if it reach end-of-content. The SkipSpaces method skip all spaces character (' ', '\f', '\n', '\r', '\t') and return the first non-space character or 0 if it reach end-of-content. The Stop method stop the parser, return the remaining unparsed content and its last position, and then call Reset to reset the internal state back to zero. The UnreadN method unread N characters and return the character its pointed to. If N greater than current position index, it will reset the read pointer index back to zero.