From 72a15b70a7eedc64f03c93c3da57394fbfb086a4 Mon Sep 17 00:00:00 2001 From: "Evgeniy A. Dushistov" Date: Thu, 6 Jul 2017 13:11:02 +0300 Subject: [PATCH] simplify parsing of integers in ifo file --- src/stardict_lib.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/stardict_lib.cpp b/src/stardict_lib.cpp index 2ea23f9..6974ff2 100644 --- a/src/stardict_lib.cpp +++ b/src/stardict_lib.cpp @@ -99,10 +99,8 @@ bool DictInfo::load_from_ifo_file(const std::string& ifofilename, return false; gchar *p3 = strchr(p2 + sizeof("\nwordcount=") - 1, '\n'); - gchar *tmpstr = (gchar *)g_memdup(p2+sizeof("\nwordcount=")-1, p3-(p2+sizeof("\nwordcount=")-1)+1); - tmpstr[p3-(p2+sizeof("\nwordcount=")-1)] = '\0'; - wordcount = atol(tmpstr); - g_free(tmpstr); + + wordcount = atol(std::string(p2+sizeof("\nwordcount=")-1, p3-(p2+sizeof("\nwordcount=")-1)).c_str()); if (istreedict) { p2 = strstr(p1,"\ntdxfilesize="); @@ -110,10 +108,9 @@ bool DictInfo::load_from_ifo_file(const std::string& ifofilename, return false; p3 = strchr(p2+ sizeof("\ntdxfilesize=")-1,'\n'); - tmpstr = (gchar *)g_memdup(p2+sizeof("\ntdxfilesize=")-1, p3-(p2+sizeof("\ntdxfilesize=")-1)+1); - tmpstr[p3-(p2+sizeof("\ntdxfilesize=")-1)] = '\0'; - index_file_size = atol(tmpstr); - g_free(tmpstr); + + index_file_size = atol(std::string(p2+sizeof("\ntdxfilesize=")-1, p3-(p2+sizeof("\ntdxfilesize=")-1)).c_str()); + } else { p2 = strstr(p1,"\nidxfilesize="); @@ -121,10 +118,7 @@ bool DictInfo::load_from_ifo_file(const std::string& ifofilename, return false; p3 = strchr(p2+ sizeof("\nidxfilesize=")-1,'\n'); - tmpstr = (gchar *)g_memdup(p2+sizeof("\nidxfilesize=")-1, p3-(p2+sizeof("\nidxfilesize=")-1)+1); - tmpstr[p3-(p2+sizeof("\nidxfilesize=")-1)] = '\0'; - index_file_size = atol(tmpstr); - g_free(tmpstr); + index_file_size = atol(std::string(p2+sizeof("\nidxfilesize=")-1, p3-(p2+sizeof("\nidxfilesize=")-1)).c_str()); } p2 = strstr(p1,"\nbookname=");