00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <basis/chaos.h>
00019 #include <basis/function.h>
00020 #include <basis/guards.h>
00021 #include <basis/istring.h>
00022 #include <opsystem/application_shell.h>
00023 #include <data_struct/static_memory_gremlin.h>
00024 #include <textual/string_manipulation.h>
00025
00026 HOOPLE_STARTUP_CODE;
00027
00028 class test_splitter : public application_shell
00029 {
00030 public:
00031 test_splitter();
00032 IMPLEMENT_CLASS_NAME("test_splitter");
00033 int execute();
00034 };
00035
00036 test_splitter::test_splitter() : application_shell("t_splitter")
00037 {}
00038
00039 istring show_limits(int min_col, int max_col)
00040 {
00041 istring to_return;
00042 for (int i = 0; i <= max_col; i++) {
00043 if (i < min_col) to_return += " ";
00044 else to_return += "+";
00045 }
00046 return to_return;
00047 }
00048
00049 #define SHOW_SPLIT(str, low, high) \
00050 string_manipulation::split_lines(str, output, low, high); \
00051 log(""); formal(temp)\
00052 log(show_limits(low, high)); \
00053 log(output + "<<<<"); \
00054 log(show_limits(low, high))
00055
00056 int test_splitter::execute()
00057 {
00058 FUNCDEF("execute");
00059
00060 istring split_1 = "This is a fairly long paragraph that will be split a few different ways to check the splitting logic. It will be interesting to see how things like spaces, and punctuation, are handled.";
00061
00062 istring output;
00063
00064 SHOW_SPLIT(split_1, 0, 1);
00065 SHOW_SPLIT(split_1, 0, 10);
00066 SHOW_SPLIT(split_1, 10, 30);
00067 SHOW_SPLIT(split_1, 20, 35);
00068 SHOW_SPLIT(split_1, 4, 50);
00069 SHOW_SPLIT(split_1, 8, 12);
00070
00071 istring split_2 = "Here's another string.\r\nThere are embedded carriage returns after every sentence.\r\nSo, this should be a good test of how those things are handled when they're seen in the body of the text.\r\nThe next one is, hey, guess what?\r\nIt's a simple LF instead of CRLF; here it comes:\nHow did that look compared the others?\nThe previous was another bare one.\r\nWhen can I stop writing this stupid paragraph?\r\nSoon hopefully.";
00072
00073 SHOW_SPLIT(split_2, 5, 20);
00074 SHOW_SPLIT(split_2, 0, 30);
00075 SHOW_SPLIT(split_2, 8, 11);
00076 SHOW_SPLIT(split_2, 28, 41);
00077 SHOW_SPLIT(split_2, 58, 79);
00078
00079 istring split_3 = "This string exists for just one purpose; it will be showing how the thing handles a really long word at the end. And that word is... califragilisticexpialadociuosberriesinmycrotcharerottingnowmamacasshelpme";
00080
00081 SHOW_SPLIT(split_3, 0, 5);
00082 SHOW_SPLIT(split_3, 10, 30);
00083
00084 istring split_4 = "This string\n\n\nhas multiple CRs gwan on.\r\n\r\nDoes this cause problems?\n\n\n\n";
00085
00086 SHOW_SPLIT(split_4, 3, 10);
00087 SHOW_SPLIT(split_4, 8, 20);
00088
00089 guards::alert_message("split_line:: work for those functions tested if the output looks right.");
00090 return 0;
00091 }
00092
00093 int main()
00094 {
00095 test_splitter to_test;
00096 return to_test.execute();
00097 }
00098