有沒有辦法在定義宏名稱時不區分大小寫?
例如,
考慮輸入流:Mov MOV moV mOv
我希望m4輸出為:mov mov mov mov
最簡單的方法是定義以下m4宏:
define(Mov,mov)
define(MOV,mov)
define(moV,mov)
define(mOv,mov)
當我們想對 4 或 5 個字母的單詞做同樣的事情時,這種方法變得乏味。有一個更好的方法嗎?
uj5u.com熱心網友回復:
如果您只想要字串轉換(希望 m4 輸出為),您可以使用translit:
translit(string, mapfrom, mapto) Transliterate the characters in the first argument from the set given by the second argument to the set given by the third. You cannot use tr(1) style abbreviations.
你的情況:
translit(`MoV',`ABCDEFGHIJKLMNOPQRSTUVWXYZ',`abcdefghijklmnopqrstuvwxyz')
讓我們創建一個名為 to_lowercase 的 m4 宏。它的定義如下所示。
define(`to_lowercase',`translit($1,`ABCDEFGHIJKLMNOPQRSTUVWXYZ',`abcdefghijklmnopqrstuvwxyz')')
現在,我們可以使用to_lowercase(Mov)', to_lowercase(mOV)'呼叫我們的宏。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/356303.html
