From 549ff85365bd1bc1dc079fd5ec86c055ab62bfd9 Mon Sep 17 00:00:00 2001 From: koldo Date: Sun, 29 Jun 2014 15:07:26 +0000 Subject: [PATCH] Functions4U: Fixed bsdiff include problem thanks to jibe git-svn-id: svn://ultimatepp.org/upp/trunk@7472 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- bazaar/Functions4U/Bsdiff/bsdiff.cpp | 4 +- bazaar/Functions4U/Functions4U.cpp | 79 +++++++++++++++++++++++----- bazaar/Functions4U/Functions4U.h | 8 ++- bazaar/Functions4U/Functions4U.upp | 3 +- bazaar/Functions4U/init | 1 + 5 files changed, 78 insertions(+), 17 deletions(-) diff --git a/bazaar/Functions4U/Bsdiff/bsdiff.cpp b/bazaar/Functions4U/Bsdiff/bsdiff.cpp index 3da8016b3..5ca9dfc01 100644 --- a/bazaar/Functions4U/Bsdiff/bsdiff.cpp +++ b/bazaar/Functions4U/Bsdiff/bsdiff.cpp @@ -37,7 +37,7 @@ __FBSDID("$FreeBSD: src/usr.bin/bsdiff/bsdiff/bsdiff.c,v 1.1 2005/08/06 01:59:05 NAMESPACE_UPP -#define MIN(x,y) (((x)<(y)) ? (x) : (y)) +#define MIN_(x,y) (((x)<(y)) ? (x) : (y)) static void split(off_t *I,off_t *V,off_t start,off_t len,off_t h) { @@ -167,7 +167,7 @@ static off_t search(off_t *I,u_char *old,off_t oldsize, }; x=st+(en-st)/2; - if(memcmp(old+I[x],nnew,MIN(oldsize-I[x],newsize))<0) { + if(memcmp(old+I[x],nnew,MIN_(oldsize-I[x],newsize))<0) { return search(I,old,oldsize,nnew,newsize,x,en,pos); } else { return search(I,old,oldsize,nnew,newsize,st,x,pos); diff --git a/bazaar/Functions4U/Functions4U.cpp b/bazaar/Functions4U/Functions4U.cpp index bbba1ee73..168106117 100644 --- a/bazaar/Functions4U/Functions4U.cpp +++ b/bazaar/Functions4U/Functions4U.cpp @@ -1083,7 +1083,7 @@ String GetLine(const String &str, int &pos) { return TrimBoth(ret); } -Value GetField(const String &str, int &pos, char separator) { +Value GetField(const String &str, int &pos, char separator, char decimalSign, bool onlyStrings) { ASSERT(separator != '\"'); String sret; int npos = str.Find(separator, pos); @@ -1107,10 +1107,13 @@ Value GetField(const String &str, int &pos, char separator) { pos = npos + 1; } } + if (onlyStrings) + return sret; + if (sret.IsEmpty()) return Null; - - double dbl = ScanDouble(sret); + + double dbl = ScanDouble(sret, NULL, decimalSign == ','); if (IsNull(dbl)) { Time t = ScanTime(sret); @@ -1129,7 +1132,7 @@ Value GetField(const String &str, int &pos, char separator) { } } -Vector > ReadCSV(const String strFile, char separator, bool bycols, bool removeRepeated) { +Vector > ReadCSV(const String strFile, char separator, bool bycols, bool removeRepeated, char decimalSign, bool onlyStrings) { Vector > result; String line; @@ -1138,7 +1141,7 @@ Vector > ReadCSV(const String strFile, char separator, bool bycol if (bycols) { line = GetLine(strFile, posLine); while (pos >= 0) { - Value name = GetField(line, pos, separator); + Value name = GetField(line, pos, separator, decimalSign, onlyStrings); //if (!IsNull(name)) { Vector &data = result.Add(); data.Add(name); @@ -1153,7 +1156,7 @@ Vector > ReadCSV(const String strFile, char separator, bool bycol int row = result[0].GetCount() - 1; for (int col = 0; col < result.GetCount(); col++) { if (pos >= 0) { - Value data = GetField(line, pos, separator); + Value data = GetField(line, pos, separator, decimalSign, onlyStrings); result[col].Add(data); if (row > 0 && result[col][row] != data) repeated = false; @@ -1177,9 +1180,12 @@ Vector > ReadCSV(const String strFile, char separator, bool bycol Vector &linedata = result.Add(); int col = 0; while (pos >= 0) { - Value data = GetField(line, pos, separator); - linedata << data; - if (row > 0 && (result[row - 1].GetCount() <= col || result[row - 1][col] != data)) + Value val = GetField(line, pos, separator, decimalSign, onlyStrings); + if (val.IsNull()) + linedata << ""; + else + linedata << val; + if (row > 0 && (result[row - 1].GetCount() <= col || result[row - 1][col] != val)) repeated = false; col++; } @@ -1194,9 +1200,53 @@ Vector > ReadCSV(const String strFile, char separator, bool bycol return result; } -String WriteCSV(Vector > &data, char separator, bool bycols) { +Vector > ReadCSVFile(const String fileName, char separator, bool bycols, bool removeRepeated, char decimalSign, bool onlyStrings) { + return ReadCSV(LoadFile(fileName), separator, bycols, removeRepeated, decimalSign, onlyStrings); +} + +bool ReadCSVFileByLine(const String fileName, Gate2&> WhenRow, char separator, char decimalSign, bool onlyStrings) { + Vector result; + + FindFile ff(fileName); + if(!ff || !ff.IsFile()) + return false; + + FileIn in(fileName); + in.ClearError(); + + for (int row = 0; true; row++) { + String line = in.GetLine(); + if (line.IsVoid()) { + WhenRow(Null, result); + return true; + } + int pos = 0; + while (pos >= 0) { + Value val = GetField(line, pos, separator, decimalSign, onlyStrings); + if (val.IsNull()) + result << ""; + else + result << val; + } + if (!WhenRow(row, result)) + return true; + result.Clear(); + } + return false; +} + +String ToStringDecimalSign(Value &val, const String &decimalSign) { + String ret = val.ToString(); + if (val.Is() && decimalSign != ".") + ret.Replace(".", decimalSign); + return ret; +} + +String WriteCSV(Vector > &data, char separator, bool bycols, char decimalSign) { String ret; + String _decimalSign(decimalSign, 1); + if (bycols) { for (int r = 0; r < data[0].GetCount(); ++r) { if (r > 0) @@ -1204,7 +1254,7 @@ String WriteCSV(Vector > &data, char separator, bool bycols) { for (int c = 0; c < data.GetCount(); ++c) { if (c > 0) ret << separator; - String str = data[c][r].ToString(); + String str = ToStringDecimalSign(data[c][r], _decimalSign); if (str.Find(separator) >= 0) ret << '\"' << str << '\"'; else @@ -1218,7 +1268,7 @@ String WriteCSV(Vector > &data, char separator, bool bycols) { for (int c = 0; c < data[r].GetCount(); ++c) { if (c > 0) ret << separator; - String str = data[r][c].ToString(); + String str = ToStringDecimalSign(data[r][c], _decimalSign); if (str.Find(separator) >= 0) ret << '\"' << str << '\"'; else @@ -1229,6 +1279,11 @@ String WriteCSV(Vector > &data, char separator, bool bycols) { return ret; } +bool WriteCSVFile(const String fileName, Vector > &data, char separator, bool bycols, char decimalSign) { + String str = WriteCSV(data, separator, bycols, decimalSign); + return SaveFile(fileName, str); +} + #ifdef PLATFORM_POSIX String FileRealName(const char *fileName) { diff --git a/bazaar/Functions4U/Functions4U.h b/bazaar/Functions4U/Functions4U.h index e507f248b..ad11fbf59 100644 --- a/bazaar/Functions4U/Functions4U.h +++ b/bazaar/Functions4U/Functions4U.h @@ -272,8 +272,12 @@ inline const double Angle(const Point_& p1, const Point_& p2) { } -Vector > ReadCSV(const String strFile, char separator = ',', bool bycols = true, bool removeRepeated = true); -String WriteCSV(Vector > &data, char separator = ',', bool bycols = true); +Vector > ReadCSV(const String strFile, char separator = ',', bool bycols = true, bool removeRepeated = true, char decimalSign = '.', bool onlyStrings = false); +Vector > ReadCSVFile(const String fileName, char separator = ',', bool bycols = true, bool removeRepeated = true, char decimalSign = '.', bool onlyStrings = false); +bool ReadCSVFileByLine(const String fileName, Gate2&> WhenRow, char separator = ',', char decimalSign = '.', bool onlyStrings = false); +String WriteCSV(Vector > &data, char separator = ',', bool bycols = true, char decimalSign = '.'); +bool WriteCSVFile(const String fileName, Vector > &data, char separator = ',', bool bycols = true, char decimalSign = '.'); + // A String based class to parse into class StringParse : public String { diff --git a/bazaar/Functions4U/Functions4U.upp b/bazaar/Functions4U/Functions4U.upp index 4986999c3..ac19eb278 100644 --- a/bazaar/Functions4U/Functions4U.upp +++ b/bazaar/Functions4U/Functions4U.upp @@ -7,7 +7,8 @@ uses plugin\jpg, plugin\gif, plugin\png, - plugin/tif; + plugin/tif, + plugin/bmp; uses(GUI) ide/Browser; diff --git a/bazaar/Functions4U/init b/bazaar/Functions4U/init index 7c49abd48..6c2df8d96 100644 --- a/bazaar/Functions4U/init +++ b/bazaar/Functions4U/init @@ -7,5 +7,6 @@ #include "plugin\gif/init" #include "plugin\png/init" #include "plugin/tif/init" +#include "plugin/bmp/init" #include "ide/Browser/init" #endif