A simple text completion, editing, and auto-correction tool written in Go. The program reads an input file, applies a series of text transformations based on special tags embedded in the text, and writes the cleaned result to an output file.
You write text with special instruction tags inside it. The program reads the text, follows the instructions, removes the tags, and saves the result.
Example:
Input: it (cap) was the best of times
Output: It was the best of times
go run . <input_file> <output_file>Example:
go run . sample.txt result.txtConverts the word before it from base 16 to base 10.
1E (hex) files were added → 30 files were added
Converts the word before it from base 2 to base 10.
It has been 10 (bin) years → It has been 2 years
Converts the word before it to UPPERCASE.
Ready, set, go (up) ! → Ready, set, GO!
Converts the N words before it to UPPERCASE.
This is so exciting (up, 2) → This is SO EXCITING
Converts the word before it to lowercase.
I should stop SHOUTING (low) → I should stop shouting
Converts the N words before it to lowercase.
IT WAS THE (low, 3) winter → it was the winter
Capitalizes the word before it.
Welcome to the Brooklyn bridge (cap) → Welcome to the Brooklyn Bridge
Capitalizes the N words before it.
it was the age of foolishness (cap, 6) → It Was The Age Of Foolishness
Punctuation marks ., , !, ?, :, ; are placed directly after the previous word with a space before the next word. Groups like ... and !? are handled correctly.
I was sitting over there ,and then BAMM !! → I was sitting over there, and then BAMM!!
I was thinking ... You were right → I was thinking... You were right
Single quote pairs have their inner padding removed so the quote marks sit flush against the content.
' awesome ' → 'awesome'
' hello world ' → 'hello world'
The article a is replaced with an before words that begin with a vowel (a, e, i, o, u) or the letter h. Capitalisation is preserved.
There it was. A amazing rock! → There it was. An amazing rock!
There is no greater agony than bearing a untold story → ... bearing an untold story
go_text_editor/
├── go.mod
├── main.go ← all transformation logic
├── main_test.go ← automated tests
└── sample.txt ← example input file
go test ./...If all tests pass you will see:
ok go_text_editor 0.003s
Input (sample.txt):
it (cap) was the best of times, it was the worst of times (up) , it was the age of wisdom, it was the age of foolishness (cap, 6) , it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of darkness, it was the spring of hope, IT WAS THE (low, 3) winter of despair.
Output (result.txt):
It was the best of times, it was the worst of TIMES, it was the age of wisdom, It Was The Age Of Foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of darkness, it was the spring of hope, it was the winter of despair.
- Go 1.16 or higher
- Standard Go packages only (no external dependencies)
Oluwatofunmi Osifowora
Built as part of the go-reloaded project at Learn2Earn.