{"id":19684245,"url":"https://github.com/elliotwutingfeng/trimmer","last_synced_at":"2025-02-27T07:23:06.687Z","repository":{"id":65712036,"uuid":"597910596","full_name":"elliotwutingfeng/trimmer","owner":"elliotwutingfeng","description":"An alternative implementation of the standard Go strings.Trim, strings.TrimLeft, and strings.TrimRight functions. Executes at least twice as fast as strings.Trim.","archived":false,"fork":false,"pushed_at":"2024-01-25T10:19:51.000Z","size":53,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-01-10T06:49:07.056Z","etag":null,"topics":["golang","rune","string","trim","unicode","whitespace"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elliotwutingfeng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-06T01:05:30.000Z","updated_at":"2024-10-06T14:05:50.000Z","dependencies_parsed_at":"2024-06-20T14:55:01.442Z","dependency_job_id":null,"html_url":"https://github.com/elliotwutingfeng/trimmer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotwutingfeng%2Ftrimmer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotwutingfeng%2Ftrimmer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotwutingfeng%2Ftrimmer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotwutingfeng%2Ftrimmer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elliotwutingfeng","download_url":"https://codeload.github.com/elliotwutingfeng/trimmer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240993391,"owners_count":19890418,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","rune","string","trim","unicode","whitespace"],"created_at":"2024-11-11T18:17:13.553Z","updated_at":"2025-02-27T07:23:06.667Z","avatar_url":"https://github.com/elliotwutingfeng.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# trimmer\n\n[![Go Reference](https://img.shields.io/badge/go-reference-blue?logo=go\u0026logoColor=white\u0026style=for-the-badge)](https://pkg.go.dev/github.com/elliotwutingfeng/trimmer)\n[![Go Report Card](https://goreportcard.com/badge/github.com/elliotwutingfeng/trimmer?style=for-the-badge)](https://goreportcard.com/report/github.com/elliotwutingfeng/trimmer)\n[![Coveralls](https://img.shields.io/coverallsCoverage/github/elliotwutingfeng/trimmer?logo=coveralls\u0026style=for-the-badge)](https://coveralls.io/github/elliotwutingfeng/trimmer?branch=main)\n\n[![GitHub license](https://img.shields.io/badge/LICENSE-BSD--3--CLAUSE-GREEN?style=for-the-badge)](LICENSE)\n\n## Summary\n\n**trimmer** is an alternative implementation of the standard Go [strings.Trim](https://pkg.go.dev/strings#Trim), [strings.TrimLeft](https://pkg.go.dev/strings#TrimLeft), and [strings.TrimRight](https://pkg.go.dev/strings#TrimRight) functions.\n\nRunes to be trimmed away are stored in a [bitset](https://github.com/karlseguin/intset) for quick retrieval.\n\nOn average, **trimmer** executes at least *twice* as fast as [strings.Trim](https://pkg.go.dev/strings#Trim).\n\nSpot any bugs? Report them [here](https://github.com/elliotwutingfeng/trimmer/issues).\n\n## Installation\n\n```sh\ngo get github.com/elliotwutingfeng/trimmer\n```\n\n## Example\n\n```go\nconst charsToTrim string = \"@👍🏽新 \"\nvar cutset *intset.Rune = MakeRuneSet(charsToTrim)\n\nfmt.Println(FastTrim(\"\", cutset, TrimBoth))\nfmt.Println(strings.Trim(\"\", \"@👍🏽新 \"))\n\nfmt.Println(FastTrim(\" \", cutset, TrimBoth))\nfmt.Println(strings.Trim(\" \", \"@👍🏽新 \"))\n\nfmt.Println(FastTrim(\"@b👍🏽新\", cutset, TrimBoth))\nfmt.Println(strings.Trim(\"@b👍🏽新\", \"@👍🏽新 \"))\n\nfmt.Println(FastTrim(\"@b👍🏽新\", cutset, TrimLeft))\nfmt.Println(strings.TrimLeft(\"@b👍🏽新\", \"@👍🏽新 \"))\n\nfmt.Println(FastTrim(\"@b👍🏽新\", cutset, TrimRight))\nfmt.Println(strings.TrimRight(\"@b👍🏽新\", \"@👍🏽新 \"))\n\nfmt.Println(FastTrim(\"@b👍新\", cutset, TrimRight))\nfmt.Println(strings.TrimRight(\"@b👍新\", \"@👍🏽新 \"))\n//Output:\n//\n//\n//b\n//b\n//b👍🏽新\n//b👍🏽新\n//@b\n//@b\n//@b\n//@b\n```\n\n## Testing\n\n```sh\nmake tests\n\n# Alternatively, run tests without race detection\n# Useful for systems that do not support the -race flag like windows/386\n# See https://tip.golang.org/src/cmd/dist/test.go\nmake tests_without_race\n```\n\n## Benchmarks\n\n```sh\nmake bench\n```\n\n### Results\n\nThe following chart indicates total time taken to trim characters `@👍🏽新` from strings in \u003chttps://github.com/minimaxir/big-list-of-naughty-strings\u003e. The strings have been modified to include prefix and/or suffix permutations with replacement of up to length 4 from the set `@👍🏽新`.\n\n```text\nCPU: AMD Ryzen 7 5800X\nTime in milliseconds (ms) | Lower is better\n\n  MakeRuneSet ▏ .08\n\n     FastTrim ▏ 252 🟦🟦🟦🟦🟦🟦🟦🟦🟦\n\n FastTrimLeft ▏ 113 🟦🟦🟦🟦\n\nFastTrimRight ▏ 167 🟦🟦🟦🟦🟦🟦\n\n         Trim ▏ 680 🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥\n\n     TrimLeft ▏ 342 🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥\n\n    TrimRight ▏ 382 🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥\n```\n\n## Limitations\n\nThe cutset (characters to be trimmed) must be initialized as `*intset.Rune` first. This incurs a small time cost.\n\n```go\nconst charsToTrim string = \"@👍🏽新 \"\nvar cutset *intset.Rune = MakeRuneSet(charsToTrim) // this incurs a small time cost\n```\n\nUse the Go Standard library if you only need to process a small amount of strings (10 strings or less) per given cutset. However, for larger amounts of strings per given cutset, **trimmer** will greatly outperform the standard library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felliotwutingfeng%2Ftrimmer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felliotwutingfeng%2Ftrimmer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felliotwutingfeng%2Ftrimmer/lists"}