c/c++语言开发共享使用m4将字符串转换为ASCII代码点

这应该是可能的,但由于我是m4的新手,我不知道如何去做,或者如何写一个算法来做到这一点(在m4中)。

编辑:

刚解决它,无论如何将来参考,我有一系列字符,它们需要被翻译成等效的ASCII码点,例如

ascii(-{COLON}-, -{:}-) => #define TKN_COLON 58 

    为了对纯m4实现感兴趣的其他人的利益,我设法创建了以下转换宏。 它必须插入引号字符以支持正常的m4引用字符。 如果这不重要,可以简化一下。

     changequote() # Change quotes so we can handle "`" and "'" # Change quotes every time this macro is called define(,)_asciiord()changequote`'dnl !>) # Convert chars one at a time in the string argument define(,,,, dnl ,0,1))ifelse(len(),1,,) $0(substr(,1))!>)!>) # Map ASCII chars to their integer index by position # Control chars are not supported. # If the comment character is changed you must alter the map accordingly define(,,,32,,,35,dnl ?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~ !>,)!>)!>) changequote # Restore normal quoting chars 

    用法:

     asciiord(`hello') --> 104, 101, 108, 108, 111 

    我用以下代码部分完成了这个

     divert(-1) changequote(-{,}-) changecom(/*,*/) define(-{ascii}-,-{#define TKN_-{}-$1 esyscmd(-{python -c "import sys; sys.stdout.write('%d'%ord('$2'))"}-)}-) divert(0)dnl 

    如果有人知道更好的方法(例如本机m4或更多便携式shell命令),我将不胜感激。

      以上就是c/c++开发分享使用m4将字符串转换为ASCII代码点相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/c-cdevelopment/549707.html

      (0)
      上一篇 2021年1月14日
      下一篇 2021年1月14日

      精彩推荐