- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有以下字符串
GOOSE BAY LATITUDE 53.27 LONGITUDE 299.60 ALTITUDE 46 M
我需要使用 Boost spirit 解析变量。
目前我有一段代码如下:
qi::rule < string::const_iterator, std::string(), asc::space_type> any_string;
any_string %= as_string [lexeme[+(asc::char_ - asc::space)]];
r = phrase_parse(first, last,
(any_string[ph::ref(station) = _1] >> "LATITUDE" >>
double_[ph::ref(lat) = _1] >> "LONGITUDE" >> double_[ph::ref(lon) = _1] >>
"ALTITUDE" >> double_[ph::ref(alt) = _1] >> "M"), asc::space);
工作正常(即存储station、lat、lon , alt 变量)如果在“纬度”之前我只有一个词。
但是,我还需要将“纬度”之前的任何内容存储到变量station 中,它应该是一个或几个(不只是两个,如示例)单词。但它不能使用“纬度”字样后的任何内容,因此纬度等仍会使用它们自己的变量。请帮助我找出正确的 Boost Spirit 表达式,以将行中看到的所有内容识别到 station,包括空格,直到特殊词(上例中的 LATITUDE) ).
最佳答案
注意事项:
asc::graph
等同于 asc::char_ - asc::space
。lexeme
如果您在没有 skipper 的情况下声明规则(另请参见 Boost spirit skipper issues)
qi::rule<It> any_string = +qi::graph_;
只是断言第一个字段中每个字符的第一个关键字的否定匹配:
+(qi::char_ - "LATITUDE")
您可以传递对 phrase_parse
API 的引用,这样您就可以不用语义操作(另请参阅 Boost Spirit: "Semantic actions are evil"?):
bool r = qi::phrase_parse(first, last,
( qi::raw [ +(qi::char_ - "LATITUDE") ] >> "LATITUDE" >>
qi::double_ >> "LONGITUDE" >>
qi::double_ >> "ALTITUDE" >>
qi::double_ >> "M"),
asc::space,
name, lat, lon, alt);
#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
namespace asc= boost::spirit::ascii;
int main()
{
typedef std::string::const_iterator It;
std::string const input("GOOSE BAY LATITUDE 53.27 LONGITUDE 299.60 ALTITUDE 46 M");
std::string name;
double lat, lon, alt;
It first(input.begin()), last(input.end());
bool r = qi::phrase_parse(first, last,
(qi::raw [ +(qi::char_ - "LATITUDE") ] >> "LATITUDE" >>
qi::double_ >> "LONGITUDE" >>
qi::double_ >> "ALTITUDE" >>
qi::double_ >> "M"),
asc::space,
name, lat, lon, alt);
if (r)
std::cout << "Parsed: '" << name << "' lat:" << lat << " lon:" << lon << " alt:" << alt << "\n";
else
std::cout << "Failed\n";
if (first != last)
std::cout << "Remaining input: '" << std::string(first, last) << "'\n";
}
关于c++ - boost spirit : how to collect "anything from line till particular word" into one variable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24619152/
我想标记一个字符串,例如 Best Beat Makers,以几乎类似于 NGram 的方式为每个单词生成标记,例如: IN: "Best Beat Makers" OUT: ["Best", "B
这个问题在这里已经有了答案: Is there a way to word-wrap long words in a div? (6 个答案) 关闭 7 年前。
我想编写一个 Python 代码来检查字符串是否包含类似于以下内容的内容: 'word.Word' => 将其替换为 'word.\nWord'。 smallLetter.capitalLetter
我想编写一个 Python 代码来检查字符串是否包含类似于以下内容的内容: 'word.Word' => 将其替换为 'word.\nWord'。 smallLetter.capitalLetter
我有以下正则表达式: ^--([\w|-]+) 我想匹配 --word --no-word 但不是: ---word ----word 最佳答案 将表情更改为 ^--(\w[-\w]*) 这需要在两个
在我的加载项中,我需要为每个打开的文档创建一个任务 Pane 。在加载项的启动方法中,我订阅了 ApplicationEvents4_Event.NewDocument 和 Application.D
我使用 word javascript api 开发了一个 word 插件。我的文档 .docx 文件在服务器上,我需要在加载项中单击按钮打开该 .docx 文档作为新的 Word 文档。 请指导我如
我需要在某个地方修复一些 CSS,因为我的文本没有环绕,如果它是一个非常长的单词,它会无限期地继续下去。 在大多数情况下,我在我的 CSS 文件中尝试了 word-wrap: break-word;
这个问题在这里已经有了答案: What is the difference between "word-break: break-all" versus "word-wrap: break-word
这个问题在这里已经有了答案: What is the differect between word-wrap and overflow-wrap? [duplicate] (1 个回答) Is t
问题详细描述如下: 给定两个单词(beginWord 和 endWord)和字典的单词列表,找出是否存在从 beginWord 到 endWord 的转换序列,这样: 一次只能更改一个字母 每个转换后
我以前没有使用过邮件合并字段,我发现的所有内容都要求您在能够插入合并字段之前选择一个数据源。我想要做的就是将字段放在 word 文档上,并且在代码使用它之前不要将其合并。我基本上是在创建文档模板。这在
将此代码放置在ThisDocument_Startup之外的Word文档级VSTO解决方案中的某个位置(创建带单击事件的功能区按钮): int zero = 0; int divideByZero =
有没有办法在没有加载项的情况下启动 MS Word(仅此实例)?我只能找到一种方法来完全禁用加载项。 最佳答案 来自Word command line switches documentation ,
有没有办法在没有加载项的情况下启动 MS Word(仅此实例)?我只找到一种方法来完全禁用加载项。 最佳答案 来自Word command line switches documentation ,您
当使用 URI 方案从网页上托管的 word 模板打开新文档时不起作用。 https://msdn.microsoft.com/en-us/library/office/dn906146.aspx 这
我的问题: overflow-wrap: break-word 和 word-break: break-word 有区别吗? 非重复: 这里有一些现有的问题,乍一看可能是重复的,但实际上不是。 Wha
我希望使用 WordNet 从一组基本术语中寻找相似术语的集合。 例如,单词'discouraged' - 潜在的同义词可能是:daunted, glum, deterred, pessimistic
部署 Word Add in 时,发布没有错误。复制文件后出现以下错误。 我没有太多事情要做。这是堆栈跟踪。 ************** Exception Text **************
我需要一个 Java 正则表达式来匹配除某个单词之外的任何单词,同时包含另一个单词。 例如字符串中不能包含Apple,但必须有Peach。 Apple and Peach - Not match Pe
我是一名优秀的程序员,十分优秀!