4.8 KiB
go-reloaded
Welcome back. Congratulations on your admission. We knew you would make it. Now time to get into projects.
Objectives
In this project you will use some of your old functions made in your old repository. You will use them with the objective of making a simple text completion/editing/auto-correction tool.
One more detail. This time the project will be corrected by auditors. The auditors will be others students and you will be an auditor as well.
We advise you to create your own tests for yourself and for when you will correct your auditees.
Introduction
- Your project must be written in Go.
- The code must respect the good practices.
- It is recommended that the code present a test file.
The tool you are about to build will receive as arguments the name of a file containing a text that needs some modifications (the input) and the name of the file the modified text should be placed in (the output). Next is a list of possible modifications that your program should execute:
-
Every instance of
(hex)
should replace the word before with the decimal version of the word (in this case the word will always be a hexadecimal number). (Ex: "1E (hex) files were added" -> "30 files were added") -
Every instance of
(bin)
should replace the word before with the decimal version of the word (in this case the word will always be a binary number). (Ex: "It has been 10 (bin) years" -> "It has been 2 years") -
Every instance of
(up)
converts the word placed before in the Uppercase version of it. (Ex: "Ready, set, go (up) !" -> "Ready, set, GO !") -
Every instance of
(low)
converts the word placed before in the Lowercase version of it. (Ex: "I should stop SHOUTING (low)" -> "I should stop shouting") -
Every instance of
(cap)
transforms the previous word in the capitalized version of it. (Ex: "Welcome to the Brooklyn bridge (cap)" -> "Welcome to the Brooklyn Bridge")- For
(low)
,(up)
,(cap)
if a number appears next to it, like so:(low, <number>)
it turns the previously specified number of words in lowercase, uppercase or capitalized accordingly. (Ex: "This is so exciting (up, 2)" -> "This is SO EXCITING")
- For
-
Every instance of the punctuations
.
,,
,!
,?
,:
and;
should be close to the previous word and with space apart from the next one. (Ex: "I was sitting over there ,and then BAMM !!" -> "I was sitting over there, and then BAMM!!").- Except if there are groups of punctuation like: '...' or '!?'. In this case the program should format the text as in the following example: "I was thinking ... You were right" -> "I was thinking... You were right".
-
The punctuation mark
'
should not have spaces if there are letters right next to it, on both sides. Otherwise, the mark should be placed to the right of the next word and the following'
mark should be placed to its left. (Ex: "I'm exactly how they describe me: ' awesome '" -> "I'm exactly how they describe me: 'awesome'")- If there are more than one word between the two
'
, the program should place the marks next to the corresponding words (Ex: "As Elton John said: ' I am the most well-known homosexual in the world '" -> "As Elton John said: 'I am the most well-known homosexual in the world'")
- If there are more than one word between the two
-
Every instance of
a
should be turned intoan
if the next word begins with a vowel or an 'h'. (Ex: "There it was. A amazing rock!" -> "There it was. An amazing rock!").
Allowed packages
- Only the standard Go packages are allowed
Usage
$ cat 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.
$ go run . sample.txt result.txt
$cat 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.
$ cat sample.txt
Simply add 42 (hex) and 10 (bin) and you will see the result is 68.
$ go run . sample.txt result.txt
$cat result.txt
Simply add 66 and 2 and you will see the result is 68.
$ cat sample.txt
There is no greater agony than bearing a untold story inside you.
$ go run . sample.txt result.txt
$cat result.txt
There is no greater agony than bearing an untold story inside you.
$ cat sample.txt
Punctuation tests are ... kinda boring ,don't you think !?
$ go run . sample.txt result.txt
$cat result.txt
Punctuation tests are... kinda boring, don't you think!?
This project will help you learn about :
- The Go file system(fs) API
- String and numbers manipulation