• 8 Functions for Transforming Text


    2 Functions for String Substitution and Analysis

    Here are some functions that operate on strings:

    $(subst from,to,text)

    Performs a textual replacement on the text text: each occurrence of from is replaced by to. The result is substituted for the function call. For example,

    $(subst ee,EE,feet on the street)
    
    • 1

    produces the value fEEt on the strEEt.

    $(patsubst pattern,replacement,text)

    Finds whitespace-separated words in text that match pattern and replaces them with replacement. Here pattern may contain a % which acts as a wildcard, matching any number of any characters within a word. If replacement also contains a %, the % is replaced by the text that matched the % in pattern. Words that do not match the pattern are kept without change in the output. Only the first % in the pattern and replacement is treated this way; any subsequent % is unchanged.

    % characters in patsubst function invocations can be quoted with preceding backslashes \. Backslashes that would otherwise quote % characters can be quoted with more backslashes. Backslashes that quote % characters or other backslashes are removed from the pattern before it is compared file names or has a stem substituted into it. Backslashes that are not in danger of quoting % characters go unmolested. For example, the pattern the\%weird\\%pattern\\ has the%weird\ preceding the operative % character, and pattern\\ following it. The final two backslashes are left alone because they cannot affect any % character.

    Whitespace between words is folded into single space characters; leading and trailing whitespace is discarded.

    For example,

    $(patsubst %.c,%.o,x.c.c bar.c)
    
    • 1

    produces the value x.c.o bar.o.

    Substitution references (see Substitution References) are a simpler way to get the effect of the patsubst function:

    $(var:pattern=replacement)
    
    • 1

    is equivalent to

    $(patsubst pattern,replacement,$(var))
    
    • 1

    The second shorthand simplifies one of the most common uses of patsubst: replacing the suffix at the end of file names.

    $(var:suffix=replacement)
    
    • 1

    is equivalent to

    $(patsubst %suffix,%replacement,$(var))
    
    • 1

    For example, you might have a list of object files:

    objects = foo.o bar.o baz.o
    
    • 1

    To get the list of corresponding source files, you could simply write:

    $(objects:.o=.c)
    
    • 1

    instead of using the general form:

    $(patsubst %.o,%.c,$(objects))
    
    • 1
  • 相关阅读:
    c#调用c++生成的dll,c++端使用opencv, c#端使用OpenCvSharp, 返回一张图像
    如何利用SD-WAN优化跨国企业访问SAP的性能
    Zookeeper中的Watch机制的原理?
    mobaxterm x11 转发Ubuntu mac
    webpack 高级
    兄弟携手!魅族与星纪时代共同发力出行领域,沈子瑜成舵手
    mysql InnoDB 索引结构
    vue3学习(四)--- watch和watchEffect监听
    boost 框架及基础类库的编译(FCL and BCL on Boost C++)
    美格智能SLM927智能模组,轻松打造功能丰富的智能终端
  • 原文地址:https://blog.csdn.net/kking_edc/article/details/127659943