Added support for MString in File
This commit is contained in:
parent
2a349c6ceb
commit
88d51cb598
25
File.cpp
25
File.cpp
@ -46,9 +46,28 @@ namespace coreutils {
|
||||
this->size = size;
|
||||
}
|
||||
|
||||
void File::read() {
|
||||
int File::read() {
|
||||
size = ::read(fd, buffer, size);
|
||||
setBufferSize(size);
|
||||
return size;
|
||||
}
|
||||
|
||||
int File::readLine() {
|
||||
setBufferSize(4096);
|
||||
size = 0;
|
||||
int len = ::read(fd, buffer + size, 1);
|
||||
if(len == 0)
|
||||
mEof = true;
|
||||
while(!mEof && (*(buffer + size) != '\n')) {
|
||||
if(*(buffer + size) != '\r') {
|
||||
// setBufferSize(size);
|
||||
++size;
|
||||
}
|
||||
len = ::read(fd, buffer + size, 1);
|
||||
if(len == 0)
|
||||
mEof = true;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
void File::write(std::string data) {
|
||||
@ -68,4 +87,8 @@ namespace coreutils {
|
||||
return zstring;
|
||||
}
|
||||
|
||||
bool File::eof() {
|
||||
return mEof;
|
||||
}
|
||||
|
||||
}
|
||||
|
5
File.h
5
File.h
@ -20,13 +20,15 @@ namespace coreutils {
|
||||
File(ZString &fileName, int mode = O_RDONLY, int authority = 0664);
|
||||
~File();
|
||||
void setBufferSize(size_t size);
|
||||
void read();
|
||||
int read();
|
||||
int readLine();
|
||||
void write(std::string data);
|
||||
void write(coreutils::ZString &data);
|
||||
std::string asString();
|
||||
coreutils::ZString& asZString();
|
||||
char *buffer;
|
||||
size_t size;
|
||||
bool eof();
|
||||
|
||||
std::string fileName;
|
||||
|
||||
@ -34,6 +36,7 @@ namespace coreutils {
|
||||
void open(std::string fileName, int mode, int authority);
|
||||
int fd;
|
||||
coreutils::ZString zstring;
|
||||
bool mEof = false;
|
||||
|
||||
};
|
||||
|
||||
|
12
MString.cpp
12
MString.cpp
@ -77,12 +77,12 @@ namespace coreutils {
|
||||
// return *this;
|
||||
// }
|
||||
|
||||
MString& MString::operator=(coreutils::ZString value) {
|
||||
if(*this == value)
|
||||
return *this;
|
||||
int len = length;
|
||||
setSize(length + value.getLength());
|
||||
memcpy(data + len, value.getData(), value.getLength());
|
||||
MString& MString::operator=(coreutils::ZString &value) {
|
||||
// if(*this == value)
|
||||
// return *this;
|
||||
setSize(value.getLength());
|
||||
memcpy(data, value.getData(), value.getLength());
|
||||
length = value.getLength();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user