|
PH Logo
Logo intepreter modeled after UCB Logo.
|
00001 /* 00002 * PredicateVerbs.cpp 00003 * 00004 * Author: Paul Hamilton 00005 * Date: 17 Aug 2011 00006 * 00007 */ 00008 00009 #include "Verbs.h" 00010 00011 #include "Thing.h" 00012 #include "World.h" 00013 00014 #include <boost/algorithm/string/case_conv.hpp> 00015 00016 using namespace std; 00017 using namespace boost; 00018 using namespace boost::algorithm; 00019 00020 namespace phlogo { 00021 00022 void Verbs::count(TokenStream *ts) { 00023 00024 pThing t = getThing(ts); 00025 if (t->isWord()) 00026 setLongResult(t->getWord().length()); 00027 else if (t->isList()) 00028 setLongResult((long)t->getList().size()); 00029 else if (t->isArray()) 00030 setLongResult((long)t->getArray().size()); 00031 else 00032 setLongResult(0); 00033 00034 } 00035 00036 void Verbs::ascii(TokenStream *ts) { 00037 00038 setLongResult(getWord(ts)[0]); 00039 00040 } 00041 00042 void Verbs::ch(TokenStream *ts) { 00043 00044 setStringResult(string(1, (char)getLong(ts))); 00045 00046 } 00047 00048 void Verbs::member(TokenStream *ts) { 00049 00050 pThing t = getThing(ts); 00051 pThing t2 = getThing(ts); 00052 pThing r(new Thing()); 00053 List l = r->allocList(); 00054 00055 if (t2->isList()) { 00056 List l2 = t2->getList(); 00057 for (tListArray::iterator i = l2.begin(); i != l2.end(); i++) { 00058 if (equal(*i, t)) { 00059 for (; i != l2.end(); i++) 00060 l.push_back(*i); 00061 break; 00062 } 00063 } 00064 } 00065 _world->setResult(r); 00066 } 00067 00068 void Verbs::lowercase(TokenStream *ts) { 00069 00070 string s = getWord(ts); 00071 to_lower(s); 00072 setStringResult(s); 00073 00074 } 00075 00076 void Verbs::uppercase(TokenStream *ts) { 00077 00078 string s = getWord(ts); 00079 to_upper(s); 00080 setStringResult(s); 00081 00082 } 00083 00084 }
1.7.4