remove old parse entry version

This commit is contained in:
James Lawrence
2021-08-31 06:18:58 -04:00
parent 57826c064d
commit 3a59228eaa
2 changed files with 0 additions and 97 deletions

View File

@@ -9,94 +9,6 @@ import (
"strings"
)
func parseDesktopEntryFileDeprecated(id string, path string) (entry desktopEntry, err error) {
lines, err := loadTextFile(path)
if err != nil {
return entry, err
}
return parseDesktopEntryDeprecated(id, lines)
}
func parseDesktopEntryDeprecated(id string, lines []string) (entry desktopEntry, err error) {
desktopID := id
name := ""
nameLoc := ""
comment := ""
commentLoc := ""
icon := ""
exec := ""
categories := ""
terminal := false
noDisplay := false
for _, l := range lines {
if strings.HasPrefix(l, "[") && l != "[Desktop Entry]" {
break
}
if strings.HasPrefix(l, "Name=") {
name = strings.Split(l, "=")[1]
continue
}
if strings.HasPrefix(l, fmt.Sprintf("Name[%s]=", strings.Split(*lang, "_")[0])) {
nameLoc = strings.Split(l, "=")[1]
continue
}
if strings.HasPrefix(l, "Comment=") {
comment = strings.Split(l, "=")[1]
continue
}
if strings.HasPrefix(l, fmt.Sprintf("Comment[%s]=", strings.Split(*lang, "_")[0])) {
commentLoc = strings.Split(l, "=")[1]
continue
}
if strings.HasPrefix(l, "Icon=") {
icon = strings.Split(l, "=")[1]
continue
}
if strings.HasPrefix(l, "Exec=") {
exec = strings.Split(l, "Exec=")[1]
disallowed := [2]string{"\"", "'"}
for _, char := range disallowed {
exec = strings.Replace(exec, char, "", -1)
}
continue
}
if strings.HasPrefix(l, "Categories=") {
categories = strings.Split(l, "Categories=")[1]
continue
}
if l == "Terminal=true" {
terminal = true
continue
}
if l == "NoDisplay=true" {
noDisplay = true
continue
}
}
// if name[ln] not found, let's try to find name[ln_LN]
if nameLoc == "" {
nameLoc = name
}
if commentLoc == "" {
commentLoc = comment
}
entry.DesktopID = desktopID
entry.Name = name
entry.NameLoc = nameLoc
entry.Comment = comment
entry.CommentLoc = commentLoc
entry.Icon = icon
entry.Exec = exec
entry.Terminal = terminal
entry.NoDisplay = noDisplay
entry.Category = categories
return entry, nil
}
func parseDesktopEntryFile(id string, path string) (e desktopEntry, err error) {
o, err := os.Open(path)
if err != nil {

View File

@@ -7,14 +7,6 @@ import (
var result desktopEntry
func BenchmarkDesktopEntryParserOld(b *testing.B) {
var entry desktopEntry
for n := 0; n < b.N; n++ {
entry, _ = parseDesktopEntryFileDeprecated("id", "./desktop-directories/game.directory")
}
result = entry
}
func BenchmarkDesktopEntryParser(b *testing.B) {
var entry desktopEntry
for n := 0; n < b.N; n++ {
@@ -41,7 +33,6 @@ func TestWhitespaceHandling(t *testing.T) {
Type = Application
Version = 1.0`
// entry, err := parseDesktopEntryDeprecated("id", strings.Split(whitespace, "\n"))
*lang = "pt"
entry, err := parseDesktopEntry("id", strings.NewReader(whitespace))
if err != nil {