t_splitter.cpp

Go to the documentation of this file.
00001 /*****************************************************************************\
00002 *                                                                             *
00003 *  Name   : test_splitter                                                     *
00004 *  Author : Chris Koeritz                                                     *
00005 *                                                                             *
00006 *  Purpose:                                                                   *
00007 *                                                                             *
00008 *    Checks out the line splitting support to make sure it is working.        *
00009 *                                                                             *
00010 *******************************************************************************
00011 * Copyright (c) 1992-$now By Author.  This program is free software; you can  *
00012 * redistribute it and/or modify it under the terms of the GNU General Public  *
00013 * License as published by the Free Software Foundation; either version 2 of   *
00014 * the License or (at your option) any later version.  This is online at:      *
00015 *     http://www.fsf.org/copyleft/gpl.html                                    *
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 

Generated on Fri Nov 28 04:29:40 2008 for HOOPLE Libraries by  doxygen 1.5.1