Commit eba0ffc1 authored by Hugo Moreau's avatar Hugo Moreau

formating: refacto

For a better readibility, better format has been used for formating.

 * main.go,
   tools/formating.go : Here.
parent ed3fa8fa
Pipeline #26329 failed with stage
in 3 minutes and 25 seconds
......@@ -551,9 +551,8 @@ func main() {
os.Exit(1)
}
src = treatGlobal(src)
if len(toIgnore) != 0 {
src = treatGlobal(src)
a, bb := tools.RewriteBlackbox(string(src), toIgnore, *output)
if err = os.MkdirAll(*output+"/blackbox", 0777); err != nil {
......@@ -567,13 +566,13 @@ func main() {
os.Exit(1)
}
src = []byte(a)
err = ioutil.WriteFile(path.Join(*output, basePackagePath), []byte(src), 0666)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
os.Exit(2)
}
err = ioutil.WriteFile(path.Join(*output, basePackagePath), []byte(src), 0666)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
os.Exit(2)
// Check if all constraints are respected
info := &types.Info{
......
......@@ -23,7 +23,6 @@ import (
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
)
......@@ -38,40 +37,39 @@ func FormatArray(src, pattern string) {
scanner := bufio.NewScanner(strings.NewReader(string(input)))
for scanner.Scan() {
if strings.Contains(scanner.Text(), pattern) {
tmp, active, count, tab := "", false, 0, 0
array, counter := []string{""}, 0
for i := 0; i < len(scanner.Text()); i++ {
tab++
if string(scanner.Text()[i]) != "}" {
array[counter] += string(scanner.Text()[i])
}
if string(scanner.Text()[i]) == "{" {
tmp += string(scanner.Text()[i])
output += tmp + "\n"
tmp, active, tab = "\t", true, 0
counter += 1
array = append(array, "")
} else if string(scanner.Text()[i]) == "," {
tmp += string(scanner.Text()[i])
output += tmp
if tab < 33 {
output += "\t"
}
if tab < 27 {
output += "\t"
}
output += "\t//" + strconv.Itoa(count) + "\n"
count++
tmp, tab = "\t", 0
counter += 1
array = append(array, "")
} else if string(scanner.Text()[i]) == "}" {
output += tmp + ","
if tab < 33 {
output += "\t"
}
if tab < 27 {
output += "\t"
}
output += "\t//" + strconv.Itoa(count) + "\n"
tmp = string(scanner.Text()[i])
output += tmp + "\n"
} else if scanner.Text()[i] != 32 || !active {
tmp += string(scanner.Text()[i])
array[counter] += ","
counter += 1
array = append(array, "")
array[counter] += string(scanner.Text()[i])
}
}
max, counter := 0, 0
for _, val := range array {
if len(val) > max {
max = len(val)
}
}
max += 1
output += fmt.Sprintf("%s\n", array[0])
output += fmt.Sprintf("\t%*s// %d\n", -max, array[1], counter)
counter += 1
for i := 2; i < len(array)-1; i++ {
output += fmt.Sprintf("\t%*s// %d\n", -max, array[i][1:], counter)
counter += 1
}
output += fmt.Sprintf("%s\n", array[len(array)-1])
} else {
output += scanner.Text() + "\n"
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment