Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go_text_editor

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.


How It Works

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

Usage

go run . <input_file> <output_file>

Example:

go run . sample.txt result.txt

Supported Transformations

(hex) — Hexadecimal to Decimal

Converts the word before it from base 16 to base 10.

1E (hex) files were added  →  30 files were added

(bin) — Binary to Decimal

Converts the word before it from base 2 to base 10.

It has been 10 (bin) years  →  It has been 2 years

(up) — Uppercase

Converts the word before it to UPPERCASE.

Ready, set, go (up) !  →  Ready, set, GO!

(up, N) — Uppercase N words

Converts the N words before it to UPPERCASE.

This is so exciting (up, 2)  →  This is SO EXCITING

(low) — Lowercase

Converts the word before it to lowercase.

I should stop SHOUTING (low)  →  I should stop shouting

(low, N) — Lowercase N words

Converts the N words before it to lowercase.

IT WAS THE (low, 3) winter  →  it was the winter

(cap) — Capitalize

Capitalizes the word before it.

Welcome to the Brooklyn bridge (cap)  →  Welcome to the Brooklyn Bridge

(cap, N) — Capitalize N words

Capitalizes the N words before it.

it was the age of foolishness (cap, 6)  →  It Was The Age Of Foolishness

Punctuation Spacing

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 Quotes

Single quote pairs have their inner padding removed so the quote marks sit flush against the content.

' awesome '                         →  'awesome'
' hello world '                     →  'hello world'

aan

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

Project Structure

go_text_editor/
├── go.mod
├── main.go        ← all transformation logic
├── main_test.go   ← automated tests
└── sample.txt     ← example input file

Running Tests

go test ./...

If all tests pass you will see:

ok      go_text_editor     0.003s

Sample Input & Output

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.

Requirements

  • Go 1.16 or higher
  • Standard Go packages only (no external dependencies)

Author

Oluwatofunmi Osifowora


Built as part of the go-reloaded project at Learn2Earn.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages