This project is a text processing tool written in Go. It reads a text file, applies several automatic corrections and formatting rules, and writes the corrected text to another file.
The goal is to simulate a simple text editor / auto-correction engine.
The program processes the input text and performs transformations such as:
- Converting binary and hexadecimal numbers to decimal
- Changing text case (uppercase, lowercase, capitalized)
- Fixing punctuation spacing
- Correcting single quotes spacing
- Replacing "a" with "an" when necessary
The program is executed with two arguments:
go run . input.txt output.txt
input.txt→ file containing the original textoutput.txt→ file where the corrected text will be saved
Example:
go run . sample.txt result.txt
If (hex) appears after a word, the previous word is treated as a hexadecimal number and converted to decimal.
Example:
Input:
1E (hex) files were added
Output:
30 files were added
If (bin) appears after a word, the previous word is treated as a binary number and converted to decimal.
Example:
Input:
It has been 10 (bin) years
Output:
It has been 2 years
The program can modify text case using special commands.
(up)
Converts the previous word to uppercase.
Example:
go (up)
→ GO
(low)
Converts the previous word to lowercase.
Example:
HELLO (low)
→ hello
(cap)
Capitalizes the previous word.
Example:
bridge (cap)
→ Bridge
Commands can also modify multiple words.
Syntax:
(up, N)
(low, N)
(cap, N)
Where N is the number of previous words to modify.
Example:
Input:
This is so exciting (up, 2)
Output:
This is SO EXCITING
The program fixes spacing around punctuation marks:
. , ! ? : ;
Rules:
- No space before punctuation
- One space after punctuation
Example:
Input:
I was sitting over there ,and then BAMM !!
Output:
I was sitting over there, and then BAMM!!
Single quotes ' must wrap words without spaces inside.
Example:
Input:
'I am awesome '
Output:
'I am awesome'
Multiple words inside quotes are also handled correctly.
Example:
Input:
' I am the best developer '
Output:
'I am the best developer'
The program replaces "a" with "an" when the next word begins with:
a e i o u h
Example:
Input:
There is a amazing rock.
Output:
There is an amazing rock.
text-tool/
│
├── main.go # Program entry point
├── functions.go # All text processing functions
└── README.md # Project documentation
The program processes text in the following order:
- Convert hexadecimal numbers
- Convert binary numbers
- Apply case modifications
- Fix punctuation spacing
- Fix quotes spacing
- Correct "a/an" usage
Each step is implemented as a separate function to keep the code clean and maintainable.
it (cap) was the best of times , it was the worst of times (up)
go run . sample.txt result.txt
It was the best of times, it was the worst of TIMES
The project only uses Go standard library packages, such as:
fmtosstringsstrconv
This project helps practice:
- File reading and writing in Go
- String manipulation
- Working with slices
- Error handling
- Writing clean and modular code
Omitogun Ayobami Rasheed