From 3a59228eaa5403a8c17ee37ef964824b073dca63 Mon Sep 17 00:00:00 2001 From: James Lawrence Date: Tue, 31 Aug 2021 06:18:58 -0400 Subject: [PATCH] remove old parse entry version --- xdgdesktop_parser.go | 88 --------------------------------------- xdgdesktop_parser_test.go | 9 ---- 2 files changed, 97 deletions(-) diff --git a/xdgdesktop_parser.go b/xdgdesktop_parser.go index 68d12c9..a305f6b 100644 --- a/xdgdesktop_parser.go +++ b/xdgdesktop_parser.go @@ -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 { diff --git a/xdgdesktop_parser_test.go b/xdgdesktop_parser_test.go index f112508..2c46883 100644 --- a/xdgdesktop_parser_test.go +++ b/xdgdesktop_parser_test.go @@ -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 {