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 示例代碼內容
-
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
參數:
- list 為欲求長度的列表名稱;
- out-var 為新創建的變量,用於存儲列表長度值。
5.1.2 GET
list(GET <list> <element index> [<index> ...] <out-var>)
功能:用於讀取列表指定索引的元素,可以同時指定多個索引。應用示例詳見代碼1.2
參數:
- list 為欲讀取元素的列表名稱;
- element index 為列表元素的索引,從0開始編號,索引0表示列表第一個元素;索引也可以為負數,-1表示列表最后一個元素,-2表示列表倒數第二個元素,以此類推。注意:當索引越界,運行會報錯。
- out-var 為新創建的變量,用於存儲指定索引元素的返回結果。當然,也是一個列表。
5.1.3 JOIN
list(JOIN <list> <glue> <out-var>)
功能:用於將列表中元素用連接字符串連接起來組成一個字符串。應用示例詳見代碼1.3
參數:
- list 為欲操作元素的列表名稱;
- glue 為連接字符串;
- out-var 為新創建的變量,用於存儲連接起來組成的字符串。注意:此時返回結果不再是一個列表。
5.1.4 SUBLIST
list(SUBLIST <list> <begin> <length> <out-var>)
功能:用於獲取列表中的一部分(子列表)。應用示例詳見代碼1.4
參數:
-
list 為欲獲取子列表的父列表名稱;
-
begin 開始索引;
-
length 子列表長度。
若length值為0,返回子列表為空列表;
若length值為-1 或 父列表長度小於begin+length值(即索引越界或超出長度),將會把父列表中從begin索引開始的所有剩余元素返回。
-
out-var 為新創建的變量,用於存儲獲取結果子列表。
5.2 查找(Search)
5.2.1 FIND
list(FIND <list> <value> <out-var>)
功能:用於查找列表中是否存在指定的元素。應用示例詳見代碼2.1
參數:
- list 為欲獲取子列表的父列表名稱;
- value 在列表中欲查找的指定元素;
- out-var 為新創建的變量,用於存儲指定元素在列表中的索引。若未找到指定元素,則返回-1。
5.3 修改(Modification)
5.3.1 APPEND
list(APPEND <list> [<element>...])
功能:用於將元素追加到列表中。應用示例詳見代碼3.1
參數:
- list 為欲添加元素的列表名稱;
- element 為欲添加的元素。
5.3.2 FILTER
list(FILTER <list> {INCLUDE | EXCLUDE} REGEX <regex>)
功能:用於根據正則表達式過濾列表中的元素。應用示例詳見代碼3.2
參數:
- list 為待過濾的列表名稱
- INCLUDE 將滿足條件的元素包含到列表中,即列表會被改變
- EXCLUDE 將滿足條件的元素排除到列表外,即列表會被改變
- REGEX 表示對列表元素進行正則表達式匹配
5.3.3 INSERT
list(INSERT <list> <index> [<element>...])
功能:用於在指定位置將元素(一個或多個)插入到列表中。應用示例詳見代碼3.3
參數:
-
list 為欲插入元素的列表名稱
-
index 插入元素的索引。
當索引為0時,表示向列表首部添加元素;注意:不是索引為0的位置處,略有差異。
當索引為列表length時,表示往列表尾部添加元素;注意:不視為越界。
-
element 為欲添加的元素。
5.3.4 POP_BACK
list(POP_BACK <list> [<out-var>...])
功能:用於將列表中最后元素移除。應用示例詳見代碼3.4
參數:
-
list 欲移除最后元素的列表名稱
-
out-var 輸出變量
-
如果未指定,則僅僅只將原列表中最后一個元素移除;
-
如果指定,會將列表最后一個元素賦值給該變量,然后再將列表最后一個元素移除。
如果指定多個輸出變量,則會依次將列表中最后一個元素賦值到輸出變量中。
如果輸出變量個數大於列表長度,則超出部分的輸出變量未定義
-
5.3.5 POP_FRONT
list(POP_FRONT <list> [<out-var>...])
功能:用於將列表中第一個元素移除。應用示例詳見代碼3.5
參數:
-
list 欲移除第一個元素的列表名稱
-
out-var 輸出變量
-
如果未指定,則僅僅只將列表中第一個元素移除;
-
如果指定,會將列表第一個元素賦值給該變量,然后再將列表第一個元素移除。
如果指定多個輸出變量,則會依次將列表中最后一個元素賦值到輸出變量中。
如果輸出變量個數大於列表長度,則超出部分的輸出變量未定義
-
5.3.6 PREPEND
list(PREPEND <list> [<element>...])
功能:用於將元素插入到列表的0索引位置。應用示例詳見代碼3.6
參數:
- list 欲插入元素的列表名稱
- element 欲插入的元素。如果待插入元素是多個,相當於把多個元素整體“平移”到列表0索引的位置。
5.3.7 REMOVE_ITEM
list(REMOVE_ITEM <list> <value>...)
功能:用於將指定的元素從列表中移除。應用示例詳見代碼3.7
參數:
- list 欲移除元素的列表名稱
- value 指定元素的值,當指定的值在列表中存在重復的時候,會刪除所有重復的值。
5.3.8 REMOVE_AT
list(REMOVE_AT <list> <index>...)
功能:用於將指定索引的元素從列表中移除。應用示例詳見代碼3.8
參數:
-
list 欲移除元素的列表名稱
-
index 指定的索引
當指定的索引不存在的時候,會提示錯誤;
如果指定的索引存在重復,則只會執行一次移除動作。
5.3.9 REMOVE_DUPLICATES
list(REMOVE_DUPLICATES <list>)
功能:用於移除列表中的重復元素。應用示例詳見代碼3.9
參數:
-
list 欲移除元素的列表名稱
如果列表中沒有重復元素,則列表不會改變。
如果列表中所有元素都是一樣的,則會保留一個。
如果有多個重復元素,則保留第一個。
5.3.10 TRANSFORM
list(TRANSFORM <list> <ACTION> [<SELECTOR>]
[OUTPUT_VARIABLE <output variable>])
功能:用於將指定的動作運用到所有或者部分指定的元素,結果可以存到原列表中或存到指定輸出新的變量中。
參數:
-
list 欲操作的列表名稱
-
action 操作選項:
-
APPEND/PREPEND: 在列表中每個元素后/前插入指定值。應用示例詳見代碼3.10.1
-
TOUPPER/TOLOWER: 將列表中每個元素轉換成大寫/小寫。應用示例詳見代碼3.10.2
-
STRIP: 去除列表中每個元素的頭尾空格。應用示例詳見代碼3.10.3
-
GENEX_STRIP: 裁剪列表中任何為產生表達式的元素。清除后列表長度不變化,因為所謂清除只是把生成表達式的位置用空元素占據。應用示例詳見代碼3.10.4
-
REPLACE: 查找並替換列表中符合條件的元素。應用示例詳見代碼3.10.5
-
-
selector 選擇選項:
-
AT 指定元素的索引。索引可以是多個。應用示例詳見代碼3.10.6
-
FOR 指定元素的范圍和迭代的步長。應用示例詳見代碼3.10.7
-
REGEX 指定正則表達式,符合正則表達式的元素才會被處理。應用示例詳見代碼3.10.8
-
-
說明:TRANSFROM命令不會改變列表元素的個數,即列表長度不會改變。
5.4 排序(Ordering)
5.4.1 REVERSE
list(REVERSE <list>)
功能:用於將整個列表反轉。應用示例詳見代碼4.1
參數:
- list 欲反轉元素列表名稱
5.4.2 SORT
list(SORT <list> [COMPARE <compare>] [CASE <case>] [ORDER <order>])
功能:用於將整個列表元素排序。應用示例詳見代碼4.2
參數:
-
list 欲排序列表名稱
-
COMPARE 指定排序方法
-
SRING 按照字母順序進行排序(默認)
-
FILE_BASENAME 如果是一系列路徑名,會使用basename進行排序
-
NATURAL 使用自然數順序排序
-
-
CASE 指明是否大小寫敏感
-
SENSITIVE 按大小寫敏感的方式進行排序(默認)
-
INSENSITIVE 按大小寫不敏感方式進行排序
-
-
ORDER 排序的順序
-
ASCENDING 按照升序排序(默認)
-
DESCENDING 按照降序排序
-