diff --git a/alib2algo/src/string/properties/StartsWith.cpp b/alib2algo/src/string/properties/StartsWith.cpp new file mode 100644 index 0000000000000000000000000000000000000000..efc98afb04bb4d7f1f57c8b8c61f0a68e2378186 --- /dev/null +++ b/alib2algo/src/string/properties/StartsWith.cpp @@ -0,0 +1,15 @@ +/* + * StartsWith.cpp + * + * Created on: 5. 11. 2014 + * Author: Jan Travnicek + */ + +#include "StartsWith.h" +#include <registration/AlgoRegistration.hpp> + +namespace { + +auto StartsWithLinearString = registration::AbstractRegister < string::properties::StartsWith, bool, const string::LinearString < > &, const string::LinearString < > & > ( string::properties::StartsWith::startsWith ); + +} /* namespace */ diff --git a/alib2algo/src/string/properties/StartsWith.h b/alib2algo/src/string/properties/StartsWith.h new file mode 100644 index 0000000000000000000000000000000000000000..8e5bd31fec95cb5ac867248a8e012e3d4c2f8570 --- /dev/null +++ b/alib2algo/src/string/properties/StartsWith.h @@ -0,0 +1,42 @@ +/* + * StartsWith.h + * + * Created on: 5. 11. 2014 + * Author: Jan Travnicek + */ + +#ifndef _STRING_STARTS_WITH_H_ +#define _STRING_STARTS_WITH_H_ + +#include <alib/set> +#include <alib/map> + +#include <string/LinearString.h> + +namespace string { + +namespace properties { + +class StartsWith { +public: + template < class SymbolType > + static bool startsWith ( const string::LinearString < SymbolType > & string, const string::LinearString < SymbolType > & prefix ); + +}; + +template < class SymbolType > +bool StartsWith::startsWith ( const string::LinearString < SymbolType > & string, const string::LinearString < SymbolType > & prefix ) { + for ( auto prefixIterator = prefix.getContent ( ).begin ( ), stringIterator = string.getContent ( ).begin ( ); prefixIterator != prefix.getContent ( ).end ( ); ++ prefixIterator, ++ stringIterator ) { + if ( stringIterator == string.getContent ( ).end ( ) ) + return false; + if ( * prefixIterator != * stringIterator ) + return false; + } + return true; +} + +} /* namespace properties */ + +} /* namespace string */ + +#endif /* _STRING_STARTS_WITH_H_ */