Code refactoring

main
Leonid Maslakov 5 months ago
parent 66e9071240
commit 6985bab960
  1. 36
      highlight_share.go
  2. 43
      highlight_share_html.go
  3. 10
      highlight_share_nums.go

@ -31,6 +31,7 @@ func replacePrefix(line string, prefixOld string, prefixNew string) string {
return line
}
// Checks if rune is a number.
func isNumber(char rune) bool {
switch char {
case '0':
@ -57,3 +58,38 @@ func isNumber(char rune) bool {
return false
}
// Checks if the string is in the list.
func isInStrList(list []string, str string) bool {
for _, item := range list {
if item == str {
return true
}
}
return false
}
// Shields HTML tags.
func shieldHTML(code string) string {
var result string = ""
codeRune := []rune(code)
for i := range codeRune {
char := string(codeRune[i])
switch char {
case "<":
result = result + "&lt"
case ">":
result = result + "&gt"
case "&":
result = result + "&amp"
default:
result = result + char
}
}
return result
}

@ -1,43 +0,0 @@
// Copyright (C) 2022 Leonid Maslakov.
// This file is part of Highlight.
// Highlight is free software: you can redistribute it
// and/or modify it under the terms of the
// GNU Affero Public License as published by the
// Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
// Highlight is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Affero Public License for more details.
// You should have received a copy of the GNU Affero Public License along with Highlight.
// If not, see <https://www.gnu.org/licenses/>.
package highlight
// Shields HTML tags.
func shieldHTML(code string) string {
var result string = ""
codeRune := []rune(code)
for i := range codeRune {
char := string(codeRune[i])
switch char {
case "<":
result = result + "&lt"
case ">":
result = result + "&gt"
case "&":
result = result + "&amp"
default:
result = result + char
}
}
return result
}

@ -108,13 +108,3 @@ func formatNumber(text string, cmdStartChars []string, cmdEndChars []string) str
return result
}
func isInStrList(list []string, char string) bool {
for _, ch := range list {
if ch == char {
return true
}
}
return false
}

Loading…
Cancel
Save