모듈:String/설명문서

< 모듈:String
하늘 (토론 | 기여)님의 2021년 5월 3일 (월) 17:25 판

이 문서는 모듈:String에 대한 설명문서입니다.

이 모듈은 Lua의 기본 문자열 함수를 위키 문서에서 사용할 수 있도록 하는 모듈입니다.

Most of the functions provided here can be invoked with named parameters, unnamed parameters, or a mixture. If named parameters are used, Mediawiki will automatically remove any leading or trailing whitespace from the parameter. Depending on the intended use, it may be advantageous to either preserve or remove such whitespace.

Global options

   ignore_errors: If set to 'true' or 1, any error condition will result in
       an empty string being returned rather than an error message.
   error_category: If an error occurs, specifies the name of a category to
       include with the error message.  The default category is
       [Category:Errors reported by Module String].
   no_category: If set to 'true' or 1, no category will be added if an error
       is generated.

모듈:String/연습장에서 모듈을 테스트 해볼 수 있습니다.

len

대상 문자열의 길이를 출력합니다. 사용법:

{{#invoke:String|len|target_string}}

또는

{{#invoke:String|len|s=target_string}}

이름 있는 변수 s 를 사용하여 함수를 불러올 경우 대상 문자열에서 선행 또는 후행 공백이 자동 삭제됩니다.

sub

이 함수는 원본 문자열에서 지정된 범위의 문자열을 반환합니다.

사용법:

{{#invoke:String|sub|원본 문자열|시작점|끝점}}

or

{{#invoke:String|sub|s=원본 문자열|i=시작점|j=끝점}}

변수

   s: 원본 문자열
   i: 반환할 문자열의 시작점, 기본값은 1
   j: 반환할 문자열의 끝점, 기본값은 문자열 끝까지

문자열의 첫 번째 문자의 인덱스는 1입니다. i나 j가 음수이면 문자열의 맨 뒤에서부터 위치가 계산됩니다. 예를 들어 abcd의 인덱스 1은 a, 인덱스 -1은 d입니다.

인덱스가 문자열의 범위를 벗어나면 오류를 반환합니다.

_match

사용법 : require("Module:String")._match strmatch = require("Module:String")._match sresult = strmatch( s, pattern, start, match, plain, nomatch )

다른 모듈에 포함해서 사용하는 함수입니다.

변수

   s: 대상 문자열
   pattern: 대상 문자열에서 찾을 문자열이나 정규식(패턴)을 입력합니다.
   start: The index within the source string to start the search.  The first
       character of the string has index 1.  Defaults to 1.
   match: In some cases it may be possible to make multiple matches on a single
       string.  This specifies which match to return, where the first match is
       match= 1.  If a negative number is specified then a match is returned
       counting from the last match.  Hence match = -1 is the same as requesting
       the last match.  Defaults to 1.
   plain: A flag indicating that the pattern should be understood as plain
       text.  Defaults to false.
   nomatch: If no match is found, output the "nomatch" value rather than an error.

For information on constructing Lua patterns, a form of [regular expression], see:

match

원본 문자열에서 정규식(패턴)과 일치하는 문자열을 찾아 반환합니다.

사용법:

{{#invoke:String|match|원본 문자열|패턴(정규식)|start_index|match_number|plain_flag|nomatch_output}}

or

{{#invoke:String|match|s=원본 문자열|pattern=패턴(정규식)|start=start_index
    |match=match_number|plain=plain_flag|nomatch=nomatch_output}}

변수

   s: 원본 문자열
   pattern: 원본 문자열에서 찾을 문자열/패턴
   start: 검색을 시작할 위치. 첫 번째 문자의 인덱스는 1입니다. 기본값은 1.
   match: In some cases it may be possible to make multiple matches on a single
       string.  This specifies which match to return, where the first match is
       match= 1.  If a negative number is specified then a match is returned
       counting from the last match.  Hence match = -1 is the same as requesting
       the last match.  Defaults to 1.
   plain: A flag indicating that the pattern should be understood as plain
       text.  Defaults to false.
   nomatch: If no match is found, output the "nomatch" value rather than an error.

If invoked using named 변수, Mediawiki will automatically remove any leading or trailing whitespace from each string. In some circumstances this is desirable, in other cases one may want to preserve the whitespace.

If the match_number or start_index are out of range for the string being queried, then this function generates an error. An error is also generated if no match is found. If one adds the parameter ignore_errors=true, then the error will be suppressed and an empty string will be returned on any failure.

For information on constructing Lua patterns, a form of [regular expression], see:

pos

This function returns a single character from the target string at position pos.

사용법:

{{#invoke:String|pos|target_string|index_value}}

or

{{#invoke:String|pos|target=target_string|pos=index_value}}

변수

   target: The string to search
   pos: The index for the character to return

If invoked using named 변수, Mediawiki will automatically remove any leading or trailing whitespace from the target string. In some circumstances this is desirable, in other cases one may want to preserve the whitespace.

The first character has an index value of 1.

If one requests a negative value, this function will select a character by counting backwards from the end of the string. In other words pos = -1 is the same as asking for the last character.

A requested value of zero, or a value greater than the length of the string returns an error.

str_find

This function duplicates the behavior of 틀:Str find, including all of its quirks. This is provided in order to support existing templates, but is NOT RECOMMENDED for new code and templates. New code is recommended to use the "find" function instead.

Returns the first index in "source" that is a match to "target". Indexing is 1-based, and the function returns -1 if the "target" string is not present in "source".

Important Note: If the "target" string is empty / missing, this function returns a value of "1", which is generally unexpected behavior, and must be accounted for separatetly.


Wikipedia-ico-48px.png
이 모듈 문서는 한국어 위키백과모듈:string 문서 27795255판에서 분기하였습니다.