fastdo  0.5.12
winux::MultiMatch类 参考

KMP多项匹配/替换 更多...

#include <strings.hpp>

struct  MatchResult
 
struct  MatchState
 

Public 类型

typedef std::vector< short > KmpNextValueArray
 
typedef std::vector< MatchStateMatchStates
 
typedef String(* ReplaceFuncType) (MultiMatch const *matchObj, int item, void *extra)
 替换函数的类型 更多...
 

Public 成员函数

 MultiMatch (String matches[], uint m, String replaces[], uint n)
 构造函数,要求匹配项和替换项 更多...
 
 MultiMatch (String matches[], uint count, ReplaceFuncType replaceFunc, void *extra=NULL)
 构造函数,要求匹配项和替换函数,若不进行替换,则replaceFunc可为NULL 更多...
 
 MultiMatch (StringArray const &matches, StringArray const &replaces)
 构造函数,要求匹配项和替换项 更多...
 
 MultiMatch (StringArray const &matches, ReplaceFuncType replaceFunc, void *extra=NULL)
 构造函数,要求匹配项和替换函数,若不进行替换,则replaceFunc可为NULL 更多...
 
 MultiMatch ()
 构造函数 更多...
 
void init (StringArray const &matches, StringArray const &replaces)
 
void init (StringArray const &matches, ReplaceFuncType replaceFunc, void *extra=NULL)
 
int addMatchReplacePair (String const &match, String const &replace)
 添加一对匹配替换项,返回要匹配的项数 更多...
 
int addMatch (String const &match)
 添加要匹配项 更多...
 
ReplaceFuncType setReplaceFunc (ReplaceFuncType newReplaceFunc, void *extra=NULL)
 设置新的替换回调函数,返回旧的替换回调函数 更多...
 
MatchResult search (String const &str, int offset=0) const
 搜索任意一项匹配(KMP) 更多...
 
MatchResult commonSearch (String const &str, int offset=0) const
 非KMP算法,仅是内部算法不同,返回值和参数同search() 更多...
 
String replace (String const &str, MatchResult(MultiMatch::*fnSearch)(String const &str, int offset) const =&MultiMatch::search) const
 替换,搜索str中的matches,并替换成replaces 更多...
 
String const & getMatchItem (int item) const
 
String getReplaceItem (int item) const
 
void setReplaceItem (int item, String const &replace)
 
void clear ()
 清空匹配项和替换项数据 更多...
 

详细描述

KMP多项匹配/替换

在文件 strings.hpp169 行定义.

成员类型定义说明

typedef std::vector<short> winux::MultiMatch::KmpNextValueArray

在文件 strings.hpp172 行定义.

在文件 strings.hpp180 行定义.

typedef String(* winux::MultiMatch::ReplaceFuncType) (MultiMatch const *matchObj, int item, void *extra)

替换函数的类型

在文件 strings.hpp188 行定义.

构造及析构函数说明

winux::MultiMatch::MultiMatch ( String  matches[],
uint  m,
String  replaces[],
uint  n 
)

构造函数,要求匹配项和替换项

winux::MultiMatch::MultiMatch ( String  matches[],
uint  count,
ReplaceFuncType  replaceFunc,
void *  extra = NULL 
)

构造函数,要求匹配项和替换函数,若不进行替换,则replaceFunc可为NULL

winux::MultiMatch::MultiMatch ( StringArray const &  matches,
StringArray const &  replaces 
)

构造函数,要求匹配项和替换项

winux::MultiMatch::MultiMatch ( StringArray const &  matches,
ReplaceFuncType  replaceFunc,
void *  extra = NULL 
)

构造函数,要求匹配项和替换函数,若不进行替换,则replaceFunc可为NULL

winux::MultiMatch::MultiMatch ( )

构造函数

之后需要自己调用addMatchReplacePair()、addMatch()、setReplaceFunc()设置相关参数

成员函数说明

int winux::MultiMatch::addMatch ( String const &  match)

添加要匹配项

int winux::MultiMatch::addMatchReplacePair ( String const &  match,
String const &  replace 
)

添加一对匹配替换项,返回要匹配的项数

void winux::MultiMatch::clear ( )

清空匹配项和替换项数据

MatchResult winux::MultiMatch::commonSearch ( String const &  str,
int  offset = 0 
) const

非KMP算法,仅是内部算法不同,返回值和参数同search()

String const& winux::MultiMatch::getMatchItem ( int  item) const
String winux::MultiMatch::getReplaceItem ( int  item) const
void winux::MultiMatch::init ( StringArray const &  matches,
StringArray const &  replaces 
)
void winux::MultiMatch::init ( StringArray const &  matches,
ReplaceFuncType  replaceFunc,
void *  extra = NULL 
)
String winux::MultiMatch::replace ( String const &  str,
MatchResult(MultiMatch::*)(String const &str, int offset) const  fnSearch = &MultiMatch::search 
) const

替换,搜索str中的matches,并替换成replaces

参数
str目标字符串
fnSearch算法选择,请指定函数(search,commonSearch)
MatchResult winux::MultiMatch::search ( String const &  str,
int  offset = 0 
) const

搜索任意一项匹配(KMP)

参数
str字符串
offset偏移,表示从哪个位置开始搜
返回
MatchResult(pos,item) 返回的pos考虑了offset值
ReplaceFuncType winux::MultiMatch::setReplaceFunc ( ReplaceFuncType  newReplaceFunc,
void *  extra = NULL 
)

设置新的替换回调函数,返回旧的替换回调函数

void winux::MultiMatch::setReplaceItem ( int  item,
String const &  replace 
)

该类的文档由以下文件生成: