Author: suokko
Date: Thu Jun 12 13:42:41 2008
New Revision: 27118

URL: http://svn.gna.org/viewcvs/wesnoth?rev=27118&view=rev
Log:
strip windows line ends from cfg files when publishing addons

Modified:
    branches/1.4/src/publish_campaign.cpp

Modified: branches/1.4/src/publish_campaign.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/1.4/src/publish_campaign.cpp?rev=27118&r1=27117&r2=27118&view=diff
==============================================================================
--- branches/1.4/src/publish_campaign.cpp (original)
+++ branches/1.4/src/publish_campaign.cpp Thu Jun 12 13:42:41 2008
@@ -129,6 +129,19 @@
 }
 
 static bool needs_escaping(char c) { return c == 0 || c == escape_char; }
+
+bool IsCR(const char& c)
+{
+       return c == 13;
+}
+static std::string strip_cr(std::string str, bool strip)
+{
+       if(!strip)
+               return str;
+       std::string::iterator new_end = std::remove_if(str.begin(), str.end(), 
IsCR);
+       str.erase(new_end, str.end());
+       return str;
+}
 
 static std::string encode_binary(const std::string& str)
 {
@@ -210,7 +223,8 @@
 static void archive_file(const std::string& path, const std::string& fname, 
config& cfg)
 {
        cfg["name"] = fname;
-       cfg["contents"] = encode_binary(read_file(path + '/' + fname));
+       bool is_cfg = (fname.size() > 4 ? (fname.substr(fname.size() - 4) == 
".cfg") :false);
+       cfg["contents"] = encode_binary(strip_cr(read_file(path + '/' + 
fname),is_cfg));
 }
 
 static void archive_dir(const std::string& path, const std::string& dirname, 
config& cfg, std::pair<std::vector<std::string>, std::vector<std::string> >& 
ignore_patterns)


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to