CMake语法—命令list

CMake语法—命令list

1 list操作列表

Reading
  list(LENGTH <list> <out-var>)
  list(GET <list> <element index> [<index> ...] <out-var>)
  list(JOIN <list> <glue> <out-var>)
  list(SUBLIST <list> <begin> <length> <out-var>)

Search
  list(FIND <list> <value> <out-var>)

Modification
  list(APPEND <list> [<element>...])
  list(FILTER <list> {INCLUDE | EXCLUDE} REGEX <regex>)
  list(INSERT <list> <index> [<element>...])
  list(POP_BACK <list> [<out-var>...])
  list(POP_FRONT <list> [<out-var>...])
  list(PREPEND <list> [<element>...])
  list(REMOVE_ITEM <list> <value>...)
  list(REMOVE_AT <list> <index>...)
  list(REMOVE_DUPLICATES <list>)
  list(TRANSFORM <list> <ACTION> [...])

Ordering
  list(REVERSE <list>)
  list(SORT <list> [...])

2 示例代码结构

目录结构

  • learn_cmake:为根目录

  • build:为CMake配置输出目录(在此例中即生成sln解决方案的地方)

  • CMakeLists.txt:CMake主脚本

  • cmake_config.bat:执行CMake配置过程的脚本(双击直接运行)

    @echo off
    set currentDir=%~dp0
    set buildDir=%currentDir%
    set cmakeOutputDir=%currentDir%\build
    cmake -S %buildDir% -B %cmakeOutputDir% -G"Visual Studio 16 2019" -T v140 -A x64
    pause
    

3 示例代码内容

  1. CMakeLists.txt主脚本

    cmake_minimum_required(VERSION 3.18)
    
    # 设置工程名称
    set(PROJECT_NAME KAIZEN)
    
    # 设置工程版本号
    set(PROJECT_VERSION "1.0.0.10" CACHE STRING "默认版本号")
    
    # 工程定义
    project (${PROJECT_NAME}
        LANGUAGES CXX C
        VERSION ${PROJECT_VERSION}
    )
    
    # 打印开始日志
    message(STATUS "########## BEGIN_TEST_LIST")
    
    ## 1 Reading
    
    ### 1.1 LENGTH
    set(list_length a b c)
    list(LENGTH list_length length)
    message(STATUS "1.1 the length of list_length : ${length}\n")
    
    ### 1.2 GET
    set(list_get wang zhang zhao liu)
    list(LENGTH list_get length)
    message(STATUS "1.2 the length of list_get : ${length}")
    list(GET list_get 0 1 -1 list_get_new)
    message(STATUS "1.2 list_get_new : ${list_get_new}\n")
    
    ### 1.3 JOIN
    set(list_join C++ JAVA Lua Python Go)
    list(LENGTH list_join length)
    message(STATUS "1.3 the length of list_join : ${length}")
    list(JOIN list_join -G- list_join_new)
    message(STATUS "1.3 list_join_new : ${list_join_new}\n")
    
    ### 1.4 SUBLIST
    set(list_sublist China America England Germany Japanese)
    list(LENGTH list_sublist length)
    message(STATUS "1.4 the length of list_sublist : ${length}")
    list(SUBLIST list_sublist 1 0 list_sublist_new_1)
    message(STATUS "1.4 list_sublist_new_1 : ${list_sublist_new_1}")
    list(SUBLIST list_sublist 1 2 list_sublist_new_2)
    message(STATUS "1.4 list_sublist_new_2 : ${list_sublist_new_2}")
    list(SUBLIST list_sublist 1 -1 list_sublist_new_3)
    message(STATUS "1.4 list_sublist_new_3 : ${list_sublist_new_3}")
    list(SUBLIST list_sublist 1 8 list_sublist_new_4)
    message(STATUS "1.4 list_sublist_new_4 : ${list_sublist_new_4}\n")
    
    ## 2 Search
    
    ### 2.1 FIND
    set(list_find peach lemon apple pear grape)
    list(LENGTH list_find length)
    message(STATUS "2.1 the length of list_find : ${length}")
    list (FIND list_find apple apple_index)
    message(STATUS "2.1 apple_index : ${apple_index}")
    list (FIND list_find balana balana_index)
    message(STATUS "2.1 balana_index : ${balana_index}\n")
    
    ## 3 modification
    
    ### 3.1 APPEND
    set(list_append 10 20 30 40)
    list(APPEND list_append 41 42 43 44)
    message(STATUS "3.1 list_append : ${list_append}\n")
    
    ### 3.2 FILTER
    set(list_filter a b c d 10 20 30 40)
    list(FILTER list_filter INCLUDE REGEX [a-z])
    message(STATUS "3.2 list_filter_include : ${list_filter}")
    list(FILTER list_filter EXCLUDE REGEX [a-z])
    message(STATUS "3.2 list_filter_exclude : ${list_filter}\n")
    
    ### 3.3 INSERT
    set(list_insert a b c d)
    list(INSERT list_insert 0 11 12 13 14)
    message(STATUS "3.3 list_insert_1 : ${list_insert}")
    list(INSERT list_insert -1 91 92 93 94)
    message(STATUS "3.3 list_insert_2 : ${list_insert}")
    list(LENGTH list_insert length)
    list(INSERT list_insert ${length} 110)
    message(STATUS "3.3 list_insert_3 : ${list_insert}\n")
    
    ### 3.4 POP_BACK
    set(list_pop_back 100 200 300)
    list(POP_BACK list_pop_back)
    message(STATUS "3.4 list_pop_back_1 : ${list_pop_back}")
    list(POP_BACK list_pop_back out-var1 out-var2 out-var3)
    message(STATUS "3.4 list_pop_back_2 : ${out-var1}、${out-var2}、${out-var3}\n")
    
    ### 3.5 POP_FRONT
    set(list_pop_front 119 110 120)
    list(POP_FRONT list_pop_front)
    message(STATUS "3.5 list_pop_front_1 : ${list_pop_front}")
    list(POP_FRONT list_pop_front out-var1 out-var2 out-var3)
    message(STATUS "3.5 list_pop_front_2 : ${out-var1}、${out-var2}、${out-var3}\n")
    
    ### 3.6 PREPEND
    set(list_PREPEND 11 12 13 14)
    list(PREPEND list_PREPEND abc)
    message(STATUS "3.6 list_PREPEND_1 : ${list_PREPEND}")
    list(PREPEND list_PREPEND b p m f d)
    message(STATUS "3.6 list_PREPEND_2 : ${list_PREPEND}\n")
    
    ### 3.7 REMOVE_ITEM
    set(list_remove_item a b c a c d e b)
    list(REMOVE_ITEM list_remove_item a)
    message(STATUS "3.7 list_remove_item_1 : ${list_remove_item}")
    list(REMOVE_ITEM list_remove_item b g)
    message(STATUS "3.7 list_remove_item_2 : ${list_remove_item}\n")
    
    ### 3.8 REMOVE_AT
    set(list_remove_at 81 82 83 84 85 86 87 88)
    list(REMOVE_AT list_remove_at 0 -1)
    message(STATUS "3.8 list_remove_at_1 : ${list_remove_at}")
    list(REMOVE_AT list_remove_at 2 2 2 2)
    message(STATUS "3.8 list_remove_at_2 : ${list_remove_at}\n")
    
    ### 3.9 REMOVE_DUPLICATES
    set(list_remove_1 a a a b b b c c c d d d)
    list(REMOVE_DUPLICATES list_remove_1)
    message(STATUS "3.9 list_remove_1 : ${list_remove_1}")
    set(list_remove_2 a a a a) 
    list(REMOVE_DUPLICATES list_remove_2)
    message(STATUS "3.9 list_remove_2 : ${list_remove_2}")
    set(list_remove_3 a b c a d a e a f)  # 多个元素重复,只保留第一个 
    list(REMOVE_DUPLICATES list_remove_3)
    message(STATUS "3.9 list_remove_3 : ${list_remove_3}\n")
    
    ### 3.10 TRANSFORM
    #### 3.10.1 ACTION-APPEND/PREPEND
    set(list_transform_append a b c d)
    list(TRANSFORM list_transform_append APPEND B OUTPUT_VARIABLE list_test_out_append)
    message(STATUS "3.10.1 list_transform_append_1 : ${list_transform_append}")
    message(STATUS "3.10.1 list_test_out_append : ${list_test_out_append}")
    list(TRANSFORM list_transform_append APPEND B)
    message(STATUS "3.10.1 list_transform_append_2 : ${list_transform_append}\n")
    
    set(list_transform_prepend 10 11 12 13)
    list(TRANSFORM list_transform_prepend PREPEND 7 OUTPUT_VARIABLE list_test_out_prepend)
    message(STATUS "3.10.1 list_transform_prepend_1 : ${list_transform_prepend}")
    message(STATUS "3.10.1 list_test_out_prepend : ${list_test_out_prepend}")
    list(TRANSFORM list_transform_prepend PREPEND 7)
    message(STATUS "3.10.1 list_transform_prepend_2 : ${list_transform_prepend}\n")
    
    #### 3.10.2 ACTION-TOUPPER/TOLOWER
    set(list_transform_toupper a bb ccc dddd)
    list(TRANSFORM list_transform_toupper TOUPPER OUTPUT_VARIABLE list_test_out_toupper)
    message(STATUS "3.10.2 list_transform_toupper_1 : ${list_transform_toupper}")
    message(STATUS "3.10.2 list_test_out_toupper : ${list_test_out_toupper}")
    list(TRANSFORM list_transform_toupper TOUPPER)
    message(STATUS "3.10.2 list_transform_toupper_2 : ${list_transform_toupper}\n")
    
    set(list_transform_tolower E FF GGG HHHH)
    list(TRANSFORM list_transform_tolower TOLOWER OUTPUT_VARIABLE list_test_out_tolower)
    message(STATUS "3.10.2 list_transform_tolower_1 : ${list_transform_tolower}")
    message(STATUS "3.10.2 list_test_out_tolower : ${list_test_out_tolower}")
    list(TRANSFORM list_transform_tolower TOLOWER)
    message(STATUS "3.10.2 list_transform_tolower_2 : ${list_transform_tolower}\n")
    
    #### 3.10.3 ACTION-STRIP
    set(list_transform_strip "  kai" "zen " " liu " "wan qian")
    list(TRANSFORM list_transform_strip STRIP OUTPUT_VARIABLE list_test_out_strip)
    message(STATUS "3.10.3 list_transform_strip : ${list_transform_strip}")
    message(STATUS "3.10.3 list_test_out_strip : ${list_test_out_strip}\n")
    
    #### 3.10.4 ACTION-GENEX_STRIP
    set(list_transform_genex_strip a b c d $<STREQUAL:"a","a"> $<STREQUAL:"a","b">)
    list(LENGTH list_transform_genex_strip len)
    message(STATUS "3.10.4 list_transform_genex_strip_1 : ${list_transform_genex_strip}")
    message(STATUS "3.10.4 old length : ${len}")
    
    list(TRANSFORM list_transform_genex_strip GENEX_STRIP OUTPUT_VARIABLE list_test_out_genex_strip)
    message(STATUS "3.10.4 list_transform_genex_strip_2 : ${list_transform_genex_strip}")
    message(STATUS "3.10.4 list_test_out_genex_strip : ${list_test_out_genex_strip}")
    list(TRANSFORM list_transform_genex_strip GENEX_STRIP)
    message(STATUS "3.10.4 list_transform_genex_strip_3 : ${list_transform_genex_strip}")
    list(LENGTH list_transform_genex_strip new_len)
    message(STATUS "3.10.4 new length : ${new_len}\n")
    
    #### 3.10.5 ACTION-REPLACE
    set(list_transform_replace aa bb cc dd 1a b2 33 44)
    list(TRANSFORM list_transform_replace REPLACE "[a-c]" 9 OUTPUT_VARIABLE list_test_out_replace)
    message(STATUS "3.10.5 list_transform_replace_1 : ${list_transform_replace}")
    message(STATUS "3.10.5 list_test_out_replace : ${list_test_out_replace}")
    list(TRANSFORM list_transform_replace REPLACE "[a-c]" 9)
    message(STATUS "3.10.5 list_transform_replace_2 : ${list_transform_replace}\n")
    
    #### 3.10.6 SELECTOR-AT
    set(list_transform_at a b c d)
    list(TRANSFORM list_transform_at APPEND Q AT 1 2 OUTPUT_VARIABLE list_test_out_at)
    message(STATUS "3.10.6 list_transform_at_1 : ${list_transform_at}")
    message(STATUS "3.10.6 list_test_out_at : ${list_test_out_at}")
    list(TRANSFORM list_transform_at APPEND Q AT 1 2)
    message(STATUS "3.10.6 list_transform_at_2 : ${list_transform_at}\n")
    
    #### 3.10.7 SELECTOR-FOR
    set(list_transform_for a b c d e f g h i j k)
    list(TRANSFORM list_transform_for APPEND Q FOR 0 -1 2 OUTPUT_VARIABLE list_test_out_for)
    message(STATUS "3.10.7 list_transform_for_1 : ${list_transform_for}")
    message(STATUS "3.10.7 list_test_out_for : ${list_test_out_for}")
    list(TRANSFORM list_transform_for APPEND Q FOR 0 -1 2)
    message(STATUS "3.10.7 list_transform_for_2 : ${list_transform_for}\n")
    
    #### 3.10.8 SELECTOR-REGEX
    set(list_transform_regex a b c d e f g h i j k)
    list(TRANSFORM list_transform_regex APPEND Q REGEX "[a-f]" OUTPUT_VARIABLE list_test_out_regex)
    message(STATUS "3.10.8 list_transform_regex_1 : ${list_transform_regex}")
    message(STATUS "3.10.8 list_test_out_regex : ${list_test_out_regex}")
    list(TRANSFORM list_transform_regex APPEND Q REGEX "[a-f]")
    message(STATUS "3.10.8 list_transform_regex_2 : ${list_transform_regex}\n")
    
    ## 4 Ordering
    ### 4.1 REVERSE
    set(list_reverse 10 20 30 40)
    message(STATUS "4.1 list_reverse_before : ${list_reverse}")
    list(REVERSE list_reverse)
    message(STATUS "4.1 list_reverse_after : ${list_reverse}\n")
    
    ### 4.2 SORT
    set(list_sort 2.2 1.7 3.5 2.1 5.9 8 1)
    list(SORT list_sort) # 以字母顺序,按照大小写不敏感方式,升序排列
    message(STATUS "4.2 list_sort_1 : ${list_sort}")
    list(SORT list_sort COMPARE NATURAL ORDER DESCENDING) # 以自然顺序,降序排列
    message(STATUS "4.2 list_sort_2 : ${list_sort}")
    
    # 打印结束日志
    message(STATUS "########## END_TEST_LIST\n")
    

4 运行结果

执行顺序运行结果如下:

-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.17763.
-- The CXX compiler identification is MSVC 19.0.24245.0
-- The C compiler identification is MSVC 19.0.24245.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- ########## BEGIN_TEST_LIST
-- 1.1 the length of list_length : 3

-- 1.2 the length of list_get : 4
-- 1.2 list_get_new : wang;zhang;liu

-- 1.3 the length of list_join : 5
-- 1.3 list_join_new : C++-G-JAVA-G-Lua-G-Python-G-Go

-- 1.4 the length of list_sublist : 5
-- 1.4 list_sublist_new_1 :
-- 1.4 list_sublist_new_2 : America;England
-- 1.4 list_sublist_new_3 : America;England;Germany;Japanese
-- 1.4 list_sublist_new_4 : America;England;Germany;Japanese

-- 2.1 the length of list_find : 5
-- 2.1 apple_index : 2
-- 2.1 balana_index : -1

-- 3.1 list_append : 10;20;30;40;41;42;43;44

-- 3.2 list_filter_include : a;b;c;d
-- 3.2 list_filter_exclude :

-- 3.3 list_insert_1 : 11;12;13;14;a;b;c;d
-- 3.3 list_insert_2 : 11;12;13;14;a;b;c;91;92;93;94;d
-- 3.3 list_insert_3 : 11;12;13;14;a;b;c;91;92;93;94;d;110

-- 3.4 list_pop_back_1 : 100;200
-- 3.4 list_pop_back_2 : 200、100、

-- 3.5 list_pop_front_1 : 110;120
-- 3.5 list_pop_front_2 : 110、120、

-- 3.6 list_PREPEND_1 : abc;11;12;13;14
-- 3.6 list_PREPEND_2 : b;p;m;f;d;abc;11;12;13;14

-- 3.7 list_remove_item_1 : b;c;c;d;e;b
-- 3.7 list_remove_item_2 : c;c;d;e

-- 3.8 list_remove_at_1 : 82;83;84;85;86;87
-- 3.8 list_remove_at_2 : 82;83;85;86;87

-- 3.9 list_remove_1 : a;b;c;d
-- 3.9 list_remove_2 : a
-- 3.9 list_remove_3 : a;b;c;d;e;f

-- 3.10.1 list_transform_append_1 : a;b;c;d
-- 3.10.1 list_test_out_append : aB;bB;cB;dB
-- 3.10.1 list_transform_append_2 : aB;bB;cB;dB

-- 3.10.1 list_transform_prepend_1 : 10;11;12;13
-- 3.10.1 list_test_out_prepend : 710;711;712;713
-- 3.10.1 list_transform_prepend_2 : 710;711;712;713

-- 3.10.2 list_transform_toupper_1 : a;bb;ccc;dddd
-- 3.10.2 list_test_out_toupper : A;BB;CCC;DDDD
-- 3.10.2 list_transform_toupper_2 : A;BB;CCC;DDDD

-- 3.10.2 list_transform_tolower_1 : E;FF;GGG;HHHH
-- 3.10.2 list_test_out_tolower : e;ff;ggg;hhhh
-- 3.10.2 list_transform_tolower_2 : e;ff;ggg;hhhh

-- 3.10.3 list_transform_strip :   kai;zen ; liu ;wan qian
-- 3.10.3 list_test_out_strip : kai;zen;liu;wan qian

-- 3.10.4 list_transform_genex_strip_1 : a;b;c;d;$<STREQUAL:"a","a">;$<STREQUAL:"a","b">
-- 3.10.4 old length : 6
-- 3.10.4 list_transform_genex_strip_2 : a;b;c;d;$<STREQUAL:"a","a">;$<STREQUAL:"a","b">
-- 3.10.4 list_test_out_genex_strip : a;b;c;d;;
-- 3.10.4 list_transform_genex_strip_3 : a;b;c;d;;
-- 3.10.4 new length : 6

-- 3.10.5 list_transform_replace_1 : aa;bb;cc;dd;1a;b2;33;44
-- 3.10.5 list_test_out_replace : 99;99;99;dd;19;92;33;44
-- 3.10.5 list_transform_replace_2 : 99;99;99;dd;19;92;33;44

-- 3.10.6 list_transform_at_1 : a;b;c;d
-- 3.10.6 list_test_out_at : a;bQ;cQ;d
-- 3.10.6 list_transform_at_2 : a;bQ;cQ;d

-- 3.10.7 list_transform_for_1 : a;b;c;d;e;f;g;h;i;j;k
-- 3.10.7 list_test_out_for : aQ;b;cQ;d;eQ;f;gQ;h;iQ;j;kQ
-- 3.10.7 list_transform_for_2 : aQ;b;cQ;d;eQ;f;gQ;h;iQ;j;kQ

-- 3.10.8 list_transform_regex_1 : a;b;c;d;e;f;g;h;i;j;k
-- 3.10.8 list_test_out_regex : aQ;bQ;cQ;dQ;eQ;fQ;g;h;i;j;k
-- 3.10.8 list_transform_regex_2 : aQ;bQ;cQ;dQ;eQ;fQ;g;h;i;j;k

-- 4.1 list_reverse_before : 10;20;30;40
-- 4.1 list_reverse_after : 40;30;20;10

-- 4.2 list_sort_1 : 1;1.7;2.1;2.2;3.5;5.9;8
-- 4.2 list_sort_2 : 8;5.9;3.5;2.2;2.1;1.7;1
-- ########## END_TEST_LIST

-- Configuring done
-- Generating done
-- Build files have been written to: F:/learn_cmake/build
请按任意键继续. . .

5 总结

5.1 读取(Reading)

5.1.1 LENGTH
list (LENGTH <list> <out-var>)

功能:用于读取列表长度。应用示例详见代码1.1

参数:

  1. list 为欲求长度的列表名称;
  2. out-var 为新创建的变量,用于存储列表长度值。
5.1.2 GET
 list(GET <list> <element index> [<index> ...] <out-var>)

功能:用于读取列表指定索引的元素,可以同时指定多个索引。应用示例详见代码1.2

参数:

  1. list 为欲读取元素的列表名称;
  2. element index 为列表元素的索引,从0开始编号,索引0表示列表第一个元素;索引也可以为负数,-1表示列表最后一个元素,-2表示列表倒数第二个元素,以此类推。注意:当索引越界,运行会报错。
  3. out-var 为新创建的变量,用于存储指定索引元素的返回结果。当然,也是一个列表。
5.1.3 JOIN
list(JOIN <list> <glue> <out-var>)

功能:用于将列表中元素用连接字符串连接起来组成一个字符串。应用示例详见代码1.3

参数:

  1. list 为欲操作元素的列表名称;
  2. glue 为连接字符串;
  3. out-var 为新创建的变量,用于存储连接起来组成的字符串。注意:此时返回结果不再是一个列表。
5.1.4 SUBLIST
list(SUBLIST <list> <begin> <length> <out-var>)

功能:用于获取列表中的一部分(子列表)。应用示例详见代码1.4

参数:

  1. list 为欲获取子列表的父列表名称;

  2. begin 开始索引;

  3. length 子列表长度。

    若length值为0,返回子列表为空列表;

    若length值为-1 或 父列表长度小于begin+length值(即索引越界或超出长度),将会把父列表中从begin索引开始的所有剩余元素返回。

  4. out-var 为新创建的变量,用于存储获取结果子列表。

5.2 查找(Search)

5.2.1 FIND
list(FIND <list> <value> <out-var>)

功能:用于查找列表中是否存在指定的元素。应用示例详见代码2.1

参数:

  1. list 为欲获取子列表的父列表名称;
  2. value 在列表中欲查找的指定元素;
  3. out-var 为新创建的变量,用于存储指定元素在列表中的索引。若未找到指定元素,则返回-1。

5.3 修改(Modification)

5.3.1 APPEND
list(APPEND <list> [<element>...])

功能:用于将元素追加到列表中。应用示例详见代码3.1

参数:

  1. list 为欲添加元素的列表名称;
  2. element 为欲添加的元素。
5.3.2 FILTER
list(FILTER <list> {INCLUDE | EXCLUDE} REGEX <regex>)

功能:用于根据正则表达式过滤列表中的元素。应用示例详见代码3.2

参数:

  1. list 为待过滤的列表名称
  2. INCLUDE 将满足条件的元素包含到列表中,即列表会被改变
  3. EXCLUDE 将满足条件的元素排除到列表外,即列表会被改变
  4. REGEX 表示对列表元素进行正则表达式匹配
5.3.3 INSERT
 list(INSERT <list> <index> [<element>...])

功能:用于在指定位置将元素(一个或多个)插入到列表中。应用示例详见代码3.3

参数:

  1. list 为欲插入元素的列表名称

  2. index 插入元素的索引。

    当索引为0时,表示向列表首部添加元素;注意:不是索引为0的位置处,略有差异。

    当索引为列表length时,表示往列表尾部添加元素;注意:不视为越界。

  3. element 为欲添加的元素。

5.3.4 POP_BACK
list(POP_BACK <list> [<out-var>...])

功能:用于将列表中最后元素移除。应用示例详见代码3.4

参数:

  1. list 欲移除最后元素的列表名称

  2. out-var 输出变量

    • 如果未指定,则仅仅只将原列表中最后一个元素移除;

    • 如果指定,会将列表最后一个元素赋值给该变量,然后再将列表最后一个元素移除。

    如果指定多个输出变量,则会依次将列表中最后一个元素赋值到输出变量中。

    如果输出变量个数大于列表长度,则超出部分的输出变量未定义

5.3.5 POP_FRONT
list(POP_FRONT <list> [<out-var>...])

功能:用于将列表中第一个元素移除。应用示例详见代码3.5

参数:

  1. list 欲移除第一个元素的列表名称

  2. out-var 输出变量

    • 如果未指定,则仅仅只将列表中第一个元素移除;

    • 如果指定,会将列表第一个元素赋值给该变量,然后再将列表第一个元素移除。

    如果指定多个输出变量,则会依次将列表中最后一个元素赋值到输出变量中。

    如果输出变量个数大于列表长度,则超出部分的输出变量未定义

5.3.6 PREPEND
list(PREPEND <list> [<element>...])

功能:用于将元素插入到列表的0索引位置。应用示例详见代码3.6

参数:

  1. list 欲插入元素的列表名称
  2. element 欲插入的元素。如果待插入元素是多个,相当于把多个元素整体“平移”到列表0索引的位置。
5.3.7 REMOVE_ITEM
list(REMOVE_ITEM <list> <value>...)

功能:用于将指定的元素从列表中移除。应用示例详见代码3.7

参数:

  1. list 欲移除元素的列表名称
  2. value 指定元素的值,当指定的值在列表中存在重复的时候,会删除所有重复的值。
5.3.8 REMOVE_AT
list(REMOVE_AT <list> <index>...)

功能:用于将指定索引的元素从列表中移除。应用示例详见代码3.8

参数:

  1. list 欲移除元素的列表名称

  2. index 指定的索引

    当指定的索引不存在的时候,会提示错误;

    如果指定的索引存在重复,则只会执行一次移除动作。

5.3.9 REMOVE_DUPLICATES
list(REMOVE_DUPLICATES <list>)

功能:用于移除列表中的重复元素。应用示例详见代码3.9

参数:

  1. list 欲移除元素的列表名称

    如果列表中没有重复元素,则列表不会改变。

    如果列表中所有元素都是一样的,则会保留一个。

    如果有多个重复元素,则保留第一个。

5.3.10 TRANSFORM
list(TRANSFORM <list> <ACTION> [<SELECTOR>]
                      [OUTPUT_VARIABLE <output variable>])

功能:用于将指定的动作运用到所有或者部分指定的元素,结果可以存到原列表中或存到指定输出新的变量中。

参数:

  1. list 欲操作的列表名称

  2. action 操作选项:

    • APPEND/PREPEND: 在列表中每个元素后/前插入指定值。应用示例详见代码3.10.1

    • TOUPPER/TOLOWER: 将列表中每个元素转换成大写/小写。应用示例详见代码3.10.2

    • STRIP: 去除列表中每个元素的头尾空格。应用示例详见代码3.10.3

    • GENEX_STRIP: 裁剪列表中任何为产生表达式的元素。清除后列表长度不变化,因为所谓清除只是把生成表达式的位置用空元素占据。应用示例详见代码3.10.4

    • REPLACE: 查找并替换列表中符合条件的元素。应用示例详见代码3.10.5

  3. selector 选择选项:

    • AT 指定元素的索引。索引可以是多个。应用示例详见代码3.10.6

    • FOR 指定元素的范围和迭代的步长。应用示例详见代码3.10.7

    • REGEX 指定正则表达式,符合正则表达式的元素才会被处理。应用示例详见代码3.10.8

  4. 说明:TRANSFROM命令不会改变列表元素的个数,即列表长度不会改变。

5.4 排序(Ordering)

5.4.1 REVERSE
list(REVERSE <list>)

功能:用于将整个列表反转。应用示例详见代码4.1

参数:

  1. list 欲反转元素列表名称
5.4.2 SORT
list(SORT <list> [COMPARE <compare>] [CASE <case>] [ORDER <order>])

功能:用于将整个列表元素排序。应用示例详见代码4.2

参数:

  1. list 欲排序列表名称

  2. COMPARE 指定排序方法

    • SRING 按照字母顺序进行排序(默认)

    • FILE_BASENAME 如果是一系列路径名,会使用basename进行排序

    • NATURAL 使用自然数顺序排序

  3. CASE 指明是否大小写敏感

    • SENSITIVE 按大小写敏感的方式进行排序(默认)

    • INSENSITIVE 按大小写不敏感方式进行排序

  4. ORDER 排序的顺序

    • ASCENDING 按照升序排序(默认)

    • DESCENDING 按照降序排序

posted @ 2022-01-19 00:56  kaizenly  阅读(1667)  评论(0编辑  收藏  举报
打赏