mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
Functions4U: Fixed bsdiff include problem thanks to jibe
git-svn-id: svn://ultimatepp.org/upp/trunk@7472 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
0228ad3655
commit
549ff85365
5 changed files with 78 additions and 17 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<Vector <Value> > ReadCSV(const String strFile, char separator, bool bycols, bool removeRepeated) {
|
||||
Vector<Vector <Value> > ReadCSV(const String strFile, char separator, bool bycols, bool removeRepeated, char decimalSign, bool onlyStrings) {
|
||||
Vector<Vector<Value> > result;
|
||||
|
||||
String line;
|
||||
|
|
@ -1138,7 +1141,7 @@ Vector<Vector <Value> > 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<Value> &data = result.Add();
|
||||
data.Add(name);
|
||||
|
|
@ -1153,7 +1156,7 @@ Vector<Vector <Value> > 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<Vector <Value> > ReadCSV(const String strFile, char separator, bool bycol
|
|||
Vector <Value> &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<Vector <Value> > ReadCSV(const String strFile, char separator, bool bycol
|
|||
return result;
|
||||
}
|
||||
|
||||
String WriteCSV(Vector<Vector <Value> > &data, char separator, bool bycols) {
|
||||
Vector<Vector <Value> > 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<int, Vector<Value>&> WhenRow, char separator, char decimalSign, bool onlyStrings) {
|
||||
Vector<Value> 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<double>() && decimalSign != ".")
|
||||
ret.Replace(".", decimalSign);
|
||||
return ret;
|
||||
}
|
||||
|
||||
String WriteCSV(Vector<Vector <Value> > &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<Vector <Value> > &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<Vector <Value> > &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<Vector <Value> > &data, char separator, bool bycols) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool WriteCSVFile(const String fileName, Vector<Vector <Value> > &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) {
|
||||
|
|
|
|||
|
|
@ -272,8 +272,12 @@ inline const double Angle(const Point_<T>& p1, const Point_<T>& p2) {
|
|||
}
|
||||
|
||||
|
||||
Vector<Vector <Value> > ReadCSV(const String strFile, char separator = ',', bool bycols = true, bool removeRepeated = true);
|
||||
String WriteCSV(Vector<Vector <Value> > &data, char separator = ',', bool bycols = true);
|
||||
Vector<Vector <Value> > ReadCSV(const String strFile, char separator = ',', bool bycols = true, bool removeRepeated = true, char decimalSign = '.', bool onlyStrings = false);
|
||||
Vector<Vector <Value> > ReadCSVFile(const String fileName, char separator = ',', bool bycols = true, bool removeRepeated = true, char decimalSign = '.', bool onlyStrings = false);
|
||||
bool ReadCSVFileByLine(const String fileName, Gate2<int, Vector<Value>&> WhenRow, char separator = ',', char decimalSign = '.', bool onlyStrings = false);
|
||||
String WriteCSV(Vector<Vector <Value> > &data, char separator = ',', bool bycols = true, char decimalSign = '.');
|
||||
bool WriteCSVFile(const String fileName, Vector<Vector <Value> > &data, char separator = ',', bool bycols = true, char decimalSign = '.');
|
||||
|
||||
|
||||
// A String based class to parse into
|
||||
class StringParse : public String {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ uses
|
|||
plugin\jpg,
|
||||
plugin\gif,
|
||||
plugin\png,
|
||||
plugin/tif;
|
||||
plugin/tif,
|
||||
plugin/bmp;
|
||||
|
||||
uses(GUI) ide/Browser;
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue