[英]Does some kind of 'strcmpf' implementation exists?
I am looking for a function that checks if a string follows (matches exactly) the pattern of data specified by the additional arguments corresponding to the format
string Like this: 我正在寻找一个函数,该函数检查字符串是否遵循(完全匹配)与format
字符串相对应的附加参数所指定的数据模式,如下所示:
/* int strcmpf (char *str1, char *format, ...); */
char *test = "Hello World !"
if(!strcmpf(test, "%s%*s %c", "Hello ", '!')
return HELLO_HAS_BEEN_SAID;
else
return PROGRAM_ISNT_POLITE;
Implementing this myself I assume will be very difficult, but such function could be very useful for semantic parsing of content. 我以为自己实现起来很困难,但是这种功能对于内容的语义解析可能非常有用。 Before I attempt to write such function myself, I need to know if there is already a library or code snippet that provides implementation of a function like this ? 在尝试自己编写此类函数之前,我需要知道是否已经有一个库或代码片段提供了此类功能的实现?
To be more specific, I need pattern-matching behavior. 更具体地说,我需要模式匹配行为。 So test
must match exactly the pattern specified by the data corresponding to the format
parameter. 因此, test
必须与匹配format
参数的数据所指定的模式完全匹配。
I need to know if there is already a library or code snippet that provides implementation of a function like this 我需要知道是否已经有一个库或代码片段提供了这种功能的实现
The standard library has no such functionality. 标准库没有此类功能。 Requests for third-party library recommendations are off-topic here, but to the extent that I understand the functionality you want, I am anyway unaware of an existing third-party implementation. 在这里,对第三方库建议的请求不在主题之列,但是就我了解您想要的功能而言,我仍然不知道现有的第三方实现。
As I said in comments, I suggest that you design the pattern-matching aspect around bona fide regular expressions instead of around printf()
or scanf()
formats (which are not entirely the same). 正如我在评论中所说,我建议您围绕善意的正则表达式设计模式匹配方面,而不是围绕printf()
或scanf()
格式(这并不完全相同)进行设计。 There are several regular expression libraries available to support that part. 有几种正则表达式库可用于支持该部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.