Chr*_*ian 5 .htaccess parsing tokenize
打赌你没有看到这个?;)
因此,我的一个项目要求我专门阅读并理解.htaccess 文件。
可悲的是,在谷歌上搜索只会让试图让自己.htaccess工作的人陷入无限的困境(对不起,无法抗拒评论)。
不管怎样,我有点害怕试图从使用它的开源项目中得到这个东西。看,在过去的几周里,我最终浪费了很多时间试图用这个策略解决我的问题,结果却发现我在阅读 RFC 和规范并按照我的方式构建东西时做得更好。
所以,如果你知道一个库,或任何(希望干净!)执行此操作的代码,请分享。同时,如果您了解有关 .htaccess 文件格式的任何文章,我相信它们会非常方便。谢谢。
注意:我几乎是多语言的,可以使用任何代码库,即使最终代码是 Delphi。我知道我的要求太多了,但我希望少看 C++。在分享 C++ 代码之前,请考虑一下我的心理健康状况。:)
编辑:嗯,我想我只是要自己手动执行此操作。文件结构似乎是:
directive arg1 arg2 argN
<begin directive section>
</end directive section>
# single line comment
Run Code Online (Sandbox Code Playgroud)
.htaccess 语法实际上与 Apache 配置本身完全相同,并且确实存在用于它的示例解析器。
如果你想自己写,你的格式大多是正确的。记住,section标签可以嵌套并且可以有参数(比如<Location />)
英文解析方法:
For each line in the file:
Strip whitespace from beginning and end of line.
If the line starts with a '#':
Parse it as a comment (or skip it)
Else, If the line starts with a '<':
If the next character is a '/', the line is a closing tag:
Seek to the next '>' to get the tag name, and pop it from the tag stack.
Else, the line is an opening tag:
Seek to the next '>' for the tag name.
If the tag, trimmed, contains whitespace:
Split on the first whitespace. The right side is params, left is the tag.
(IfModule, Location, etc use this)
Push the tag name to the tag stack.
Else, the line is a directive:
Split the line on whitespace. This is the directive and params.
Run Code Online (Sandbox Code Playgroud)
只需添加报价处理即可。
| 归档时间: |
|
| 查看次数: |
558 次 |
| 最近记录: |