1 Star 0 Fork 0

清风徐来 / escape-f

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

C 转义字符转换

Escape-f Language license

escape-f 将字符串中常见的 C 转义字符转换为 Fortran 字符,从而我们可以书写如下代码:

print *, escape("Hello,\n\tworld!\n&
                & I'm Fortran!")

而不是,不方便地:

print *, "Hello,"//achar(10)//achar(9)//"world!"//new_line("a")//&
         " I'm Fortran!"

从而方便我们在某些场景下使用 C 转义字符风格串联地书写整个字符串,实现换行和回车等常用功能,一般用以向屏幕或文本文件输出字符串。 escape-f 使用了 OpenMP 并行和内置函数,因此在大量字符串转换时,也可以获得较高的性能。

支持的C转义字符

转义字符 含义 实现情况
\a 响铃 (BEL) ✔️
\b 退格 (BS) ✔️
\f 换页 (FF) ✔️
\n 换行 (LF) ✔️
\r 回车 (CR) ✔️
\t 水平制表符 (HT) ✔️
\v 垂直制表符 (VT) ✔️
\0 空字符 (NUL) ✔️
\? 问号 ✔️
\' 单引号 ✔️
\" 双引号 ✔️
\\ 反斜杠 ✔️
\ddd 以八进制数 ddd 表示的字符
\xhh 以十六进制数 hh 表示的字符

Warning

\0 在 Fortran 中无显著意义,escape-f 会将它从字符串中移除。

使用

仅支持 Fpm 构建,其他构建工具请自行复制源码,代码在 ifort/ifx/gfortran 下测试通过。

在 Fpm 项目中使用 escape-f,将以下内容添加到 fpm.toml 中:

[dependencies]
escape-f = { git = "https://gitee.com/zoziha/escape-f" }

在 Fortran 代码中使用:

fpm run --example --all
program example_escape

    use escape_module, only: escape
    implicit none

    print *, escape("Hello, \n\v\tworld!\n\0")
    print *, escape("Hello,\n&
                &\tworld!\n&
                & I'm Fortran!")

end program example_escape
!> Hello, 
!>
!>       world!
!>
!> Hello,
!>        world!
!> I'm Fortran!

文档

生成并打开 FORD 文档:

ford FORD-doc.md
start build/ford/index.html     # Windows 打开网页

相关字符串函数库

  • Fortty: 在Fortran中创建丰富多彩的终端应用程序。
  • Fortran-regex: tiny-regex-c正则表达式库的Fortran端口。
  • M_strings: Fortran字符串操作。
MIT License Copyright (c) 2023, ZUO Zhihua. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

将字符串中常见的 C 转义字符转换为 Fortran 字符 展开 收起
FORTRAN
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
FORTRAN
1
https://gitee.com/zoziha/escape-f.git
git@gitee.com:zoziha/escape-f.git
zoziha
escape-f
escape-f
main

搜索帮助