mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-19 01:25:05 -04:00
Work on split
This commit is contained in:
parent
a5b839ca25
commit
0af7422ca8
@ -37,6 +37,7 @@ public:
|
||||
//Accessors
|
||||
|
||||
size_t size() const;
|
||||
size_t capacity() const;
|
||||
bool empty() const;
|
||||
|
||||
const char* c_str() const;
|
||||
|
@ -15,5 +15,9 @@ vector<string> split(const string& s){
|
||||
}
|
||||
}
|
||||
|
||||
if(!current.empty()){
|
||||
parts.push_back(current);
|
||||
}
|
||||
|
||||
return move(parts);
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "disks.hpp"
|
||||
#include "string.hpp"
|
||||
#include "vector.hpp"
|
||||
#include "algorithms.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
@ -418,7 +419,23 @@ void unmount_command(const char* ){
|
||||
}
|
||||
|
||||
void ls_command(const char* params){
|
||||
string p(params);
|
||||
string par(params);
|
||||
k_printf("%h\n", reinterpret_cast<size_t>(&par));
|
||||
|
||||
k_printf("%h\n", reinterpret_cast<size_t>(par.c_str()));
|
||||
k_print_line(par.size());
|
||||
k_print_line(par.capacity());
|
||||
|
||||
k_print_line(par.c_str());
|
||||
k_print_line(par);
|
||||
|
||||
auto parts = split(par);
|
||||
|
||||
k_print_line(parts.size());
|
||||
|
||||
for(auto& part : parts){
|
||||
k_print_line(part);
|
||||
}
|
||||
|
||||
if(!disks::mounted_partition() || !disks::mounted_disk()){
|
||||
k_print_line("Nothing is mounted");
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "string.hpp"
|
||||
#include "utils.hpp"
|
||||
#include "console.hpp"
|
||||
|
||||
string::string(){
|
||||
_size = 0;
|
||||
@ -24,9 +25,10 @@ string::string(const string& rhs){
|
||||
*this = rhs;
|
||||
}
|
||||
|
||||
//TODO Does not seem to work
|
||||
string& string::operator=(const string& rhs){
|
||||
if(this != &rhs){
|
||||
if(_capacity < rhs._capacity){
|
||||
if(_capacity < rhs._capacity || !_data){
|
||||
if(_data){
|
||||
delete[] _data;
|
||||
}
|
||||
@ -63,15 +65,21 @@ string& string::operator=(string&& rhs){
|
||||
}
|
||||
|
||||
string::~string(){
|
||||
delete[] _data;
|
||||
if(_data){
|
||||
delete[] _data;
|
||||
}
|
||||
}
|
||||
|
||||
size_t string::size() const {
|
||||
return _size;
|
||||
}
|
||||
|
||||
size_t string::capacity() const {
|
||||
return _capacity;
|
||||
}
|
||||
|
||||
bool string::empty() const {
|
||||
return _size;
|
||||
return !_size;
|
||||
}
|
||||
|
||||
const char* string::c_str() const {
|
||||
@ -103,17 +111,17 @@ string& string::operator+=(char c){
|
||||
}
|
||||
|
||||
string::iterator string::begin(){
|
||||
return _data;
|
||||
return iterator(&_data[0]);
|
||||
}
|
||||
|
||||
string::iterator string::end(){
|
||||
return _data + _size;
|
||||
return iterator(&_data[_size]);
|
||||
}
|
||||
|
||||
string::const_iterator string::begin() const {
|
||||
return _data;
|
||||
return const_iterator(&_data[0]);
|
||||
}
|
||||
|
||||
string::const_iterator string::end() const {
|
||||
return _data + _size;
|
||||
return const_iterator(&_data[_size]);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user