remove old parse entry version
This commit is contained in:
@@ -9,94 +9,6 @@ import (
|
|||||||
"strings"
|
"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) {
|
func parseDesktopEntryFile(id string, path string) (e desktopEntry, err error) {
|
||||||
o, err := os.Open(path)
|
o, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -7,14 +7,6 @@ import (
|
|||||||
|
|
||||||
var result desktopEntry
|
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) {
|
func BenchmarkDesktopEntryParser(b *testing.B) {
|
||||||
var entry desktopEntry
|
var entry desktopEntry
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
@@ -41,7 +33,6 @@ func TestWhitespaceHandling(t *testing.T) {
|
|||||||
Type = Application
|
Type = Application
|
||||||
Version = 1.0`
|
Version = 1.0`
|
||||||
|
|
||||||
// entry, err := parseDesktopEntryDeprecated("id", strings.Split(whitespace, "\n"))
|
|
||||||
*lang = "pt"
|
*lang = "pt"
|
||||||
entry, err := parseDesktopEntry("id", strings.NewReader(whitespace))
|
entry, err := parseDesktopEntry("id", strings.NewReader(whitespace))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user