add string demo
This commit is contained in:
54
c_os/user/demo/StringDemo.cc
Normal file
54
c_os/user/demo/StringDemo.cc
Normal file
@ -0,0 +1,54 @@
|
||||
#include "user/demo/StringDemo.h"
|
||||
#include "kernel/Globals.h"
|
||||
#include "user/lib/String.h"
|
||||
|
||||
void StringDemo::run() {
|
||||
kout.lock();
|
||||
kout.clear();
|
||||
|
||||
log.info() << "Allocating new string" << endl;
|
||||
bse::string str1 = "This is a dynamically allocated string!";
|
||||
kout << str1 << endl;
|
||||
|
||||
log.info() << "Reassign string" << endl;
|
||||
str1 = "Hello";
|
||||
kout << str1 << " has length " << str1.size() << endl;
|
||||
kout << "Again with strlen: Hello has length " << bse::strlen("Hello") << endl;
|
||||
|
||||
kout << "Adding strings: " << str1 << " + World" << endl;
|
||||
log.info() << "Adding strings" << endl;
|
||||
str1 = str1 + " World";
|
||||
kout << str1 << endl;
|
||||
|
||||
kout << "Hello += World" << endl;
|
||||
log.info() << "Hello += World" << endl;
|
||||
bse::string str3 = "Hello";
|
||||
str3 += " World";
|
||||
kout << str3 << endl;
|
||||
|
||||
kout << "String iterator!" << endl;
|
||||
for (const char c : str1) {
|
||||
kout << c << " ";
|
||||
}
|
||||
kout << endl;
|
||||
|
||||
log.info() << "Allocating new string" << endl;
|
||||
bse::string str2 = "Hello World";
|
||||
kout << "str1 == str2: " << static_cast<int>(str1 == str2) << endl;
|
||||
kout << "strcmp(Hello, Hello): " << bse::strcmp("Hello", "Hello") << endl;
|
||||
|
||||
log.info() << "Reassign str2" << endl;
|
||||
str2 = "Hello";
|
||||
|
||||
bse::array<char, 5> arr;
|
||||
arr[0] = 'H';
|
||||
arr[1] = 'e';
|
||||
arr[2] = 'l';
|
||||
arr[3] = 'l';
|
||||
arr[4] = 'o';
|
||||
kout << "bse::array<char, 5> to bse::string: " << arr << ", size: " << ((bse::string)arr).size() << endl;
|
||||
kout << "(bse::string)arr (" << arr << ") == str2 (" << str2 << "): " << static_cast<int>((bse::string)arr == str2) << endl;
|
||||
|
||||
kout.unlock();
|
||||
scheduler.exit();
|
||||
}
|
||||
16
c_os/user/demo/StringDemo.h
Normal file
16
c_os/user/demo/StringDemo.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef __StringDemo_include__
|
||||
#define __StringDemo_include__
|
||||
|
||||
#include "kernel/Globals.h"
|
||||
|
||||
class StringDemo : public Thread {
|
||||
private:
|
||||
StringDemo(const StringDemo& copy) = delete;
|
||||
|
||||
public:
|
||||
StringDemo() : Thread("StringDemo") {}
|
||||
|
||||
void run() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user