Add rudimentary string searching based on std::string capabilities

This commit is contained in:
Jason Turner 2009-07-07 03:29:41 +00:00
parent 24a4d61e44
commit 8ae2e6cc8b
3 changed files with 43 additions and 0 deletions

View File

@ -204,6 +204,24 @@ def zip_with(f, x, y) { \
def zip(x, y) { \
zip_with(collate, x, y); \
}\
def find(str, substr) { \
return int(find(str, substr, size_t(0))); \
} \
def rfind(str, substr) { \
return int(rfind(str, substr, size_t(-1))); \
} \
def find_first_of(str, list) { \
return int(find_first_of(str, list, size_t(0))); \
} \
def find_last_of(str, list) { \
return int(find_last_of(str, list, size_t(-1))); \
} \
def find_first_not_of(str, list) { \
return int(find_first_not_of(str, list, size_t(0))); \
} \
def find_last_not_of(str, list) { \
return int(find_last_not_of(str, list, size_t(-1))); \
} \
)
#endif /* CHAISCRIPT_PRELUDE_HPP_ */

View File

@ -70,6 +70,17 @@ namespace dispatchkit
}
}
template<typename P1>
P1 construct_pod(Boxed_POD_Value v)
{
if (v.m_isfloat)
{
return (v.d);
} else {
return (v.i);
}
}
template<typename P1, typename P2>
bool equals(P1 p1, P2 p2)
@ -351,6 +362,12 @@ namespace dispatchkit
add_copy_constructor<T>(s, type);
}
template<typename T>
void add_construct_pod(Dispatch_Engine &s, const std::string &type)
{
register_function(s, &construct_pod<T>, type);
}
template<typename T, typename U>
void add_constructor_overload(Dispatch_Engine &s, const std::string &type)
{
@ -398,6 +415,7 @@ namespace dispatchkit
add_basic_constructors<T>(s, name);
add_oper_assign<T>(s);
add_oper_assign_pod<T>(s);
add_construct_pod<T>(s, name);
add_opers_arithmetic<T>(s);
add_opers_arithmetic_modify_pod<T>(s);
register_function(s, &to_string<T>, "to_string");

View File

@ -218,6 +218,13 @@ namespace dispatchkit
add_opers_comparison<String>(system);
bootstrap_random_access_container<String>(system, type);
bootstrap_sequence<String>(system, type);
typedef typename String::size_type (String::*find_func)(const String &, typename String::size_type) const;
register_function(system, find_func(&String::find), "find");
register_function(system, find_func(&String::rfind), "rfind");
register_function(system, find_func(&String::find_first_of), "find_first_of");
register_function(system, find_func(&String::find_last_of), "find_last_of");
register_function(system, find_func(&String::find_first_not_of), "find_first_not_of");
register_function(system, find_func(&String::find_last_not_of), "find_last_not_of");
}
}