add: strings and projects
This commit is contained in:
54
20-project-spam-masker/01-step-1/main.go
Normal file
54
20-project-spam-masker/01-step-1/main.go
Normal file
@@ -0,0 +1,54 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
/*
|
||||
✅ #1- Get and check the input
|
||||
✅ #2- Create a byte buffer and use it as the output
|
||||
✅ #3- Write input to the buffer as it is and print it
|
||||
✅ #4- Detect the link
|
||||
#5- Mask the link
|
||||
#6- Stop masking when whitespace is detected
|
||||
#7- Put a http:// prefix in front of the masked link
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
args := os.Args[1:]
|
||||
if len(args) != 1 {
|
||||
fmt.Println("gimme somethin' to mask!")
|
||||
return
|
||||
}
|
||||
|
||||
const (
|
||||
link = "http://"
|
||||
nlink = len(link)
|
||||
)
|
||||
|
||||
var (
|
||||
text = args[0]
|
||||
size = len(text)
|
||||
buf = make([]byte, 0, size)
|
||||
)
|
||||
|
||||
for i := 0; i < size; i++ {
|
||||
buf = append(buf, text[i])
|
||||
|
||||
// slice the input and look for the link pattern
|
||||
// do not slice it when it goes beyond the input text's capacity
|
||||
if len(text[i:]) >= nlink && text[i:i+nlink] == link {
|
||||
}
|
||||
}
|
||||
|
||||
// print out the buffer as text (string)
|
||||
fmt.Println(string(buf))
|
||||
}
|
7
20-project-spam-masker/01-step-1/spam.txt
Normal file
7
20-project-spam-masker/01-step-1/spam.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
Hi guys,
|
||||
|
||||
Here is my new spammy webpage http://www.mysuperpage.com <-- This is my website!
|
||||
|
||||
Please click on the link now!!!
|
||||
|
||||
When you click, I will be rich, thanks!
|
Reference in New Issue
Block a user