From b444057ab8d70de5c510ee5e40fe69f84b431f7f Mon Sep 17 00:00:00 2001 From: salano_ym <53254905+salano-ym@users.noreply.github.com> Date: Sat, 30 Mar 2024 17:26:36 +0000 Subject: [PATCH 01/10] Str:encode_uri --- docs/std.md | 4 ++++ src/interpreter/lib/std.ts | 5 +++++ test/index.ts | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/docs/std.md b/docs/std.md index 4e888add..99fe7365 100644 --- a/docs/std.md +++ b/docs/std.md @@ -131,6 +131,10 @@ _codePoints_の各要素は 0 以上、10FFFF16 以下である必要 UTF-8のバイト列を表す数値の配列から文字を生成します。 _bytes_の各要素は 0 以上、255 以下である必要があります。 +### #Str:encode_uri(v: str): str +v をURIとしてエンコードした文字列を返します。ただし以下の文字はエンコードされません。 +`A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; , / ? : @ & = + $ #` + ## :: Arr ### @Arr:create(_length_: num, _initial_?: value): arr 長さが`length`の配列を作成します。 diff --git a/src/interpreter/lib/std.ts b/src/interpreter/lib/std.ts index 469cba07..2aa7af86 100644 --- a/src/interpreter/lib/std.ts +++ b/src/interpreter/lib/std.ts @@ -498,6 +498,11 @@ export const std: Record = { return a.value; })))); }), + + 'Str:encode_uri': FN_NATIVE(([v]) => { + assertString(v); + return STR(encodeURI(v.value)); + }), //#endregion //#region Arr diff --git a/test/index.ts b/test/index.ts index 3c62c840..cb32cf10 100644 --- a/test/index.ts +++ b/test/index.ts @@ -3057,6 +3057,13 @@ describe('std', () => { `); eq(res, NULL); }); + + test.concurrent('encode_uri', async () => { + const res = await exe(` + <: Str:encode_uri("https://example.com/?q=あいちゃん") + `); + eq(res, STR('https://example.com/?q=%E3%81%82%E3%81%84%E3%81%A1%E3%82%83%E3%82%93')); + }); }); describe('Error', () => { From d4a5cc77708cb9a09383260e62bd90acba0070cd Mon Sep 17 00:00:00 2001 From: salano_ym <53254905+salano-ym@users.noreply.github.com> Date: Sat, 30 Mar 2024 17:28:51 +0000 Subject: [PATCH 02/10] Str:encode_uri_component --- docs/std.md | 4 ++++ src/interpreter/lib/std.ts | 5 +++++ test/index.ts | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/docs/std.md b/docs/std.md index 99fe7365..db1d8514 100644 --- a/docs/std.md +++ b/docs/std.md @@ -135,6 +135,10 @@ _bytes_の各要素は 0 以上、255 以下である必要があります。 v をURIとしてエンコードした文字列を返します。ただし以下の文字はエンコードされません。 `A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; , / ? : @ & = + $ #` +### #Str:encode_uri_component(v: str): str +v をURIとしてエンコードした文字列を返します。ただし以下の文字はエンコードされません。 +`A-Z a-z 0-9 - _ . ! ~ * ' ( )` + ## :: Arr ### @Arr:create(_length_: num, _initial_?: value): arr 長さが`length`の配列を作成します。 diff --git a/src/interpreter/lib/std.ts b/src/interpreter/lib/std.ts index 2aa7af86..a41eb7da 100644 --- a/src/interpreter/lib/std.ts +++ b/src/interpreter/lib/std.ts @@ -502,6 +502,11 @@ export const std: Record = { 'Str:encode_uri': FN_NATIVE(([v]) => { assertString(v); return STR(encodeURI(v.value)); + }), + + 'Str:encode_uri_component': FN_NATIVE(([v]) => { + assertString(v); + return STR(encodeURIComponent(v.value)); }), //#endregion diff --git a/test/index.ts b/test/index.ts index cb32cf10..d53e13e1 100644 --- a/test/index.ts +++ b/test/index.ts @@ -3064,6 +3064,13 @@ describe('std', () => { `); eq(res, STR('https://example.com/?q=%E3%81%82%E3%81%84%E3%81%A1%E3%82%83%E3%82%93')); }); + + test.concurrent('encode_uri_component', async () => { + const res = await exe(` + <: Str:encode_uri_component("https://example.com/?q=あいちゃん") + `); + eq(res, STR('https%3A%2F%2Fexample.com%2F%3Fq%3D%E3%81%82%E3%81%84%E3%81%A1%E3%82%83%E3%82%93')); + }); }); describe('Error', () => { From 0cfbaf7db26895588912ae2bc213f53e424a700e Mon Sep 17 00:00:00 2001 From: salano_ym <53254905+salano-ym@users.noreply.github.com> Date: Sat, 30 Mar 2024 17:29:47 +0000 Subject: [PATCH 03/10] Str:decode_uri --- docs/std.md | 4 ++++ src/interpreter/lib/std.ts | 5 +++++ test/index.ts | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/docs/std.md b/docs/std.md index db1d8514..35343f18 100644 --- a/docs/std.md +++ b/docs/std.md @@ -139,6 +139,10 @@ v をURIとしてエンコードした文字列を返します。ただし以下 v をURIとしてエンコードした文字列を返します。ただし以下の文字はエンコードされません。 `A-Z a-z 0-9 - _ . ! ~ * ' ( )` +### #Str:decode_uri(v: str): str +v をURIとしてエスケープシーケンスをデコードした文字列を返します。 +ただし`Str:encode_uri`でエンコードされないエスケープシーケンスはデコードされません。 + ## :: Arr ### @Arr:create(_length_: num, _initial_?: value): arr 長さが`length`の配列を作成します。 diff --git a/src/interpreter/lib/std.ts b/src/interpreter/lib/std.ts index a41eb7da..71439105 100644 --- a/src/interpreter/lib/std.ts +++ b/src/interpreter/lib/std.ts @@ -507,6 +507,11 @@ export const std: Record = { 'Str:encode_uri_component': FN_NATIVE(([v]) => { assertString(v); return STR(encodeURIComponent(v.value)); + }), + + 'Str:decode_uri': FN_NATIVE(([v]) => { + assertString(v); + return STR(decodeURI(v.value)); }), //#endregion diff --git a/test/index.ts b/test/index.ts index d53e13e1..07e0a149 100644 --- a/test/index.ts +++ b/test/index.ts @@ -3071,6 +3071,13 @@ describe('std', () => { `); eq(res, STR('https%3A%2F%2Fexample.com%2F%3Fq%3D%E3%81%82%E3%81%84%E3%81%A1%E3%82%83%E3%82%93')); }); + + test.concurrent('decode_uri', async () => { + const res = await exe(` + <: Str:decode_uri("https%3A%2F%2Fexample.com%2F%3Fq%3D%E3%81%82%E3%81%84%E3%81%A1%E3%82%83%E3%82%93") + `); + eq(res, STR('https%3A%2F%2Fexample.com%2F%3Fq%3Dあいちゃん')); + }); }); describe('Error', () => { From bbecdf65707301910fdd29addba43c454b8574be Mon Sep 17 00:00:00 2001 From: salano_ym <53254905+salano-ym@users.noreply.github.com> Date: Sat, 30 Mar 2024 17:30:50 +0000 Subject: [PATCH 04/10] Str:decode_uri_component --- docs/std.md | 3 +++ src/interpreter/lib/std.ts | 5 +++++ test/index.ts | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/docs/std.md b/docs/std.md index 35343f18..a8fccf07 100644 --- a/docs/std.md +++ b/docs/std.md @@ -143,6 +143,9 @@ v をURIとしてエンコードした文字列を返します。ただし以下 v をURIとしてエスケープシーケンスをデコードした文字列を返します。 ただし`Str:encode_uri`でエンコードされないエスケープシーケンスはデコードされません。 +### #Str:decode_uri_component(v: str): str +v をURIとしてエスケープシーケンスをデコードした文字列を返します。 + ## :: Arr ### @Arr:create(_length_: num, _initial_?: value): arr 長さが`length`の配列を作成します。 diff --git a/src/interpreter/lib/std.ts b/src/interpreter/lib/std.ts index 71439105..e7d530cd 100644 --- a/src/interpreter/lib/std.ts +++ b/src/interpreter/lib/std.ts @@ -513,6 +513,11 @@ export const std: Record = { assertString(v); return STR(decodeURI(v.value)); }), + + 'Str:decode_uri_component': FN_NATIVE(([v]) => { + assertString(v); + return STR(decodeURIComponent(v.value)); + }), //#endregion //#region Arr diff --git a/test/index.ts b/test/index.ts index 07e0a149..fc1b5805 100644 --- a/test/index.ts +++ b/test/index.ts @@ -3078,6 +3078,13 @@ describe('std', () => { `); eq(res, STR('https%3A%2F%2Fexample.com%2F%3Fq%3Dあいちゃん')); }); + + test.concurrent('decode_uri_component', async () => { + const res = await exe(` + <: Str:decode_uri_component("https%3A%2F%2Fexample.com%2F%3Fq%3D%E3%81%82%E3%81%84%E3%81%A1%E3%82%83%E3%82%93") + `); + eq(res, STR('https://example.com/?q=あいちゃん')); + }); }); describe('Error', () => { From d599f8f3ce7dcafbf449eda42186aec7f8f9b2fb Mon Sep 17 00:00:00 2001 From: salano_ym <53254905+salano-ym@users.noreply.github.com> Date: Sat, 30 Mar 2024 17:32:40 +0000 Subject: [PATCH 05/10] Update CHANGELOG.md Str:encode_uri Str:encode_uri_component Str:decode_uri Str:decode_uri_component --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a54dd98..3987e087 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - `arr.incl`の引数の型制限を廃止 - `Date:millisecond`を追加 - `arr.fill`, `arr.repeat`, `Arr:create`を追加 +- `Str:encode_uri`, `Str:encode_uri_component`, `Str:decode_uri`, `Str:decode_uri_component`を追加 # 0.17.0 - `package.json`を修正 From 1d094fd3838daf7f1accbf3d0abb5233d76b16b8 Mon Sep 17 00:00:00 2001 From: salano_ym <53254905+salano-ym@users.noreply.github.com> Date: Sat, 30 Mar 2024 17:38:12 +0000 Subject: [PATCH 06/10] =?UTF-8?q?doc=E3=81=AE=E6=9B=B8=E5=BC=8F=E3=81=8C?= =?UTF-8?q?=E9=96=93=E9=81=95=E3=81=A3=E3=81=A6=E3=81=84=E3=82=8B=E3=81=AE?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/std.md | 18 +++++++++--------- translations/en/docs/std.md | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/std.md b/docs/std.md index a8fccf07..fc4f9a91 100644 --- a/docs/std.md +++ b/docs/std.md @@ -110,40 +110,40 @@ _date_ を渡した場合、_date_に対応するミリ秒、 型: `str` 改行コード(LF)です。 -### #Str:lt(a: str, b: str): num +### @Str:lt(a: str, b: str): num a < b ならば -1、a == b ならば 0、a > b ならば 1 を返します。 arr.sortの比較関数として使用できます。 -### #Str:gt(a: str, b: str): num +### @Str:gt(a: str, b: str): num a > b ならば -1、a == b ならば 0、a < b ならば 1 を返します。 arr.sortの比較関数として使用できます。 -### #Str:from_codepoint(codepoint: num): str +### @Str:from_codepoint(codepoint: num): str Unicodeのコードポイントから文字を生成します。 _codepoint_ は 0 以上、10FFFF16 以下である必要があります。 -### #Str:from_unicode_codepoints(_codePoints_: `arr`): str +### @Str:from_unicode_codepoints(_codePoints_: `arr`): str Unicodeのコードポイント列を表す数値の配列から文字を生成します。 _codePoints_の各要素は 0 以上、10FFFF16 以下である必要があります。 -### #Str:from_utf8_bytes(_bytes_: `arr`): str +### @Str:from_utf8_bytes(_bytes_: `arr`): str UTF-8のバイト列を表す数値の配列から文字を生成します。 _bytes_の各要素は 0 以上、255 以下である必要があります。 -### #Str:encode_uri(v: str): str +### @Str:encode_uri(v: str): str v をURIとしてエンコードした文字列を返します。ただし以下の文字はエンコードされません。 `A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; , / ? : @ & = + $ #` -### #Str:encode_uri_component(v: str): str +### @Str:encode_uri_component(v: str): str v をURIとしてエンコードした文字列を返します。ただし以下の文字はエンコードされません。 `A-Z a-z 0-9 - _ . ! ~ * ' ( )` -### #Str:decode_uri(v: str): str +### @Str:decode_uri(v: str): str v をURIとしてエスケープシーケンスをデコードした文字列を返します。 ただし`Str:encode_uri`でエンコードされないエスケープシーケンスはデコードされません。 -### #Str:decode_uri_component(v: str): str +### @Str:decode_uri_component(v: str): str v をURIとしてエスケープシーケンスをデコードした文字列を返します。 ## :: Arr diff --git a/translations/en/docs/std.md b/translations/en/docs/std.md index 67d36237..32098a9e 100644 --- a/translations/en/docs/std.md +++ b/translations/en/docs/std.md @@ -113,19 +113,19 @@ Generates a numeric value from a hexadecimal string. Type: `str`. Newline code (LF). -### #Str:lt(a: str, b: str): num +### @Str:lt(a: str, b: str): num Returns -1 if a < b, 0 if a == b, or 1 if a > b. Using this as a comparison function for `arr.sort`, the array is sorted in ascending lexicographic order. -### #Str:gt(a: str, b: str): num +### @Str:gt(a: str, b: str): num Returns -1 if a > b, 0 if a == b, or 1 if a < b. Using this as the comparison function for `arr.sort`, the array is sorted in descending lexicographic order. -### #Str:from_codepoint(codepoint: num): str +### @Str:from_codepoint(codepoint: num): str Generates character from unicode code point. _codepoint_ must be greater than or equal to 0 and less than or equal to 10FFFFFF16. Multiple arguments are not supported yet. From 7458adccd8e6adceeebd5305da7e2f5ae53f8c12 Mon Sep 17 00:00:00 2001 From: salano_ym <53254905+salano-ym@users.noreply.github.com> Date: Sun, 31 Mar 2024 09:32:13 +0000 Subject: [PATCH 07/10] =?UTF-8?q?encode=E7=B3=BB=E3=81=AEdoc=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/std.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/std.md b/docs/std.md index fc4f9a91..759ed24d 100644 --- a/docs/std.md +++ b/docs/std.md @@ -131,20 +131,20 @@ _codePoints_の各要素は 0 以上、10FFFF16 以下である必要 UTF-8のバイト列を表す数値の配列から文字を生成します。 _bytes_の各要素は 0 以上、255 以下である必要があります。 -### @Str:encode_uri(v: str): str -v をURIとしてエンコードした文字列を返します。ただし以下の文字はエンコードされません。 +### @Str:encode_uri(uri: str): str +uri をURIとしてエンコードした文字列を返します。以下の文字はエンコードされません。 `A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; , / ? : @ & = + $ #` -### @Str:encode_uri_component(v: str): str -v をURIとしてエンコードした文字列を返します。ただし以下の文字はエンコードされません。 +### @Str:encode_uri_component(text: str): str +text をURI構成要素としてエンコードした文字列を返します。以下の文字はエンコードされません。 `A-Z a-z 0-9 - _ . ! ~ * ' ( )` -### @Str:decode_uri(v: str): str -v をURIとしてエスケープシーケンスをデコードした文字列を返します。 -ただし`Str:encode_uri`でエンコードされないエスケープシーケンスはデコードされません。 +### @Str:decode_uri(encoded_uri: str): str +encoded_uri をエンコードされたURIとしてデコードした文字列を返します。 +`Str:encode_uri`でエンコードされないエスケープシーケンスはデコードされません。 -### @Str:decode_uri_component(v: str): str -v をURIとしてエスケープシーケンスをデコードした文字列を返します。 +### @Str:decode_uri_component(encoded_text: str): str +encoded_text をエンコードされたURI構成要素としてデコードした文字列を返します。 ## :: Arr ### @Arr:create(_length_: num, _initial_?: value): arr From ab686d4a472341ef4398593c79b97d1aa99a34f3 Mon Sep 17 00:00:00 2001 From: salano_ym <53254905+salano-ym@users.noreply.github.com> Date: Sun, 31 Mar 2024 10:48:02 +0000 Subject: [PATCH 08/10] =?UTF-8?q?encode=E7=B3=BB=E9=96=A2=E6=95=B0?= =?UTF-8?q?=E3=81=AE=E5=90=8D=E5=89=8D=E7=A9=BA=E9=96=93=E3=82=92Str:?= =?UTF-8?q?=E3=81=8B=E3=82=89Uri:=E3=81=AB=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- docs/std.md | 11 ++++++----- src/interpreter/lib/std.ts | 12 +++++++----- test/index.ts | 10 ++++++---- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3987e087..fce03652 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ - `arr.incl`の引数の型制限を廃止 - `Date:millisecond`を追加 - `arr.fill`, `arr.repeat`, `Arr:create`を追加 -- `Str:encode_uri`, `Str:encode_uri_component`, `Str:decode_uri`, `Str:decode_uri_component`を追加 +- `Uri:encode_uri`, `Uri:encode_uri_component`, `Uri:decode_uri`, `Uri:decode_uri_component`を追加 # 0.17.0 - `package.json`を修正 diff --git a/docs/std.md b/docs/std.md index 759ed24d..88cb72c8 100644 --- a/docs/std.md +++ b/docs/std.md @@ -131,19 +131,20 @@ _codePoints_の各要素は 0 以上、10FFFF16 以下である必要 UTF-8のバイト列を表す数値の配列から文字を生成します。 _bytes_の各要素は 0 以上、255 以下である必要があります。 -### @Str:encode_uri(uri: str): str +## :: Uri +### @Uri:encode_uri(uri: str): str uri をURIとしてエンコードした文字列を返します。以下の文字はエンコードされません。 `A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; , / ? : @ & = + $ #` -### @Str:encode_uri_component(text: str): str +### @Uri:encode_uri_component(text: str): str text をURI構成要素としてエンコードした文字列を返します。以下の文字はエンコードされません。 `A-Z a-z 0-9 - _ . ! ~ * ' ( )` -### @Str:decode_uri(encoded_uri: str): str +### @Uri:decode_uri(encoded_uri: str): str encoded_uri をエンコードされたURIとしてデコードした文字列を返します。 -`Str:encode_uri`でエンコードされないエスケープシーケンスはデコードされません。 +`Uri:encode_uri`でエンコードされないエスケープシーケンスはデコードされません。 -### @Str:decode_uri_component(encoded_text: str): str +### @Uri:decode_uri_component(encoded_text: str): str encoded_text をエンコードされたURI構成要素としてデコードした文字列を返します。 ## :: Arr diff --git a/src/interpreter/lib/std.ts b/src/interpreter/lib/std.ts index e7d530cd..df46d6f5 100644 --- a/src/interpreter/lib/std.ts +++ b/src/interpreter/lib/std.ts @@ -498,23 +498,25 @@ export const std: Record = { return a.value; })))); }), - - 'Str:encode_uri': FN_NATIVE(([v]) => { + //#endregion + + //#region Uri + 'Uri:encode_uri': FN_NATIVE(([v]) => { assertString(v); return STR(encodeURI(v.value)); }), - 'Str:encode_uri_component': FN_NATIVE(([v]) => { + 'Uri:encode_uri_component': FN_NATIVE(([v]) => { assertString(v); return STR(encodeURIComponent(v.value)); }), - 'Str:decode_uri': FN_NATIVE(([v]) => { + 'Uri:decode_uri': FN_NATIVE(([v]) => { assertString(v); return STR(decodeURI(v.value)); }), - 'Str:decode_uri_component': FN_NATIVE(([v]) => { + 'Uri:decode_uri_component': FN_NATIVE(([v]) => { assertString(v); return STR(decodeURIComponent(v.value)); }), diff --git a/test/index.ts b/test/index.ts index fc1b5805..a6fb2888 100644 --- a/test/index.ts +++ b/test/index.ts @@ -3057,31 +3057,33 @@ describe('std', () => { `); eq(res, NULL); }); + }); + describe('Uri', () => { test.concurrent('encode_uri', async () => { const res = await exe(` - <: Str:encode_uri("https://example.com/?q=あいちゃん") + <: Uri:encode_uri("https://example.com/?q=あいちゃん") `); eq(res, STR('https://example.com/?q=%E3%81%82%E3%81%84%E3%81%A1%E3%82%83%E3%82%93')); }); test.concurrent('encode_uri_component', async () => { const res = await exe(` - <: Str:encode_uri_component("https://example.com/?q=あいちゃん") + <: Uri:encode_uri_component("https://example.com/?q=あいちゃん") `); eq(res, STR('https%3A%2F%2Fexample.com%2F%3Fq%3D%E3%81%82%E3%81%84%E3%81%A1%E3%82%83%E3%82%93')); }); test.concurrent('decode_uri', async () => { const res = await exe(` - <: Str:decode_uri("https%3A%2F%2Fexample.com%2F%3Fq%3D%E3%81%82%E3%81%84%E3%81%A1%E3%82%83%E3%82%93") + <: Uri:decode_uri("https%3A%2F%2Fexample.com%2F%3Fq%3D%E3%81%82%E3%81%84%E3%81%A1%E3%82%83%E3%82%93") `); eq(res, STR('https%3A%2F%2Fexample.com%2F%3Fq%3Dあいちゃん')); }); test.concurrent('decode_uri_component', async () => { const res = await exe(` - <: Str:decode_uri_component("https%3A%2F%2Fexample.com%2F%3Fq%3D%E3%81%82%E3%81%84%E3%81%A1%E3%82%83%E3%82%93") + <: Uri:decode_uri_component("https%3A%2F%2Fexample.com%2F%3Fq%3D%E3%81%82%E3%81%84%E3%81%A1%E3%82%83%E3%82%93") `); eq(res, STR('https://example.com/?q=あいちゃん')); }); From 3deebcf6a2dfd9fd916ea642595a3d77ea10216d Mon Sep 17 00:00:00 2001 From: salano_ym <53254905+salano-ym@users.noreply.github.com> Date: Sun, 31 Mar 2024 15:39:02 +0000 Subject: [PATCH 09/10] =?UTF-8?q?Uri:encode=E7=B3=BB=E3=81=AE=E9=96=A2?= =?UTF-8?q?=E6=95=B0=E5=90=8D=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- docs/std.md | 10 +++++----- src/interpreter/lib/std.ts | 8 ++++---- test/index.ts | 16 ++++++++-------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fce03652..6b8a2571 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ - `arr.incl`の引数の型制限を廃止 - `Date:millisecond`を追加 - `arr.fill`, `arr.repeat`, `Arr:create`を追加 -- `Uri:encode_uri`, `Uri:encode_uri_component`, `Uri:decode_uri`, `Uri:decode_uri_component`を追加 +- `Uri:encode_full`, `Uri:encode_component`, `Uri:decode_full`, `Uri:decode_component`を追加 # 0.17.0 - `package.json`を修正 diff --git a/docs/std.md b/docs/std.md index 88cb72c8..efad9a3a 100644 --- a/docs/std.md +++ b/docs/std.md @@ -132,19 +132,19 @@ UTF-8のバイト列を表す数値の配列から文字を生成します。 _bytes_の各要素は 0 以上、255 以下である必要があります。 ## :: Uri -### @Uri:encode_uri(uri: str): str +### @Uri:encode_full(uri: str): str uri をURIとしてエンコードした文字列を返します。以下の文字はエンコードされません。 `A-Z a-z 0-9 - _ . ! ~ * ' ( ) ; , / ? : @ & = + $ #` -### @Uri:encode_uri_component(text: str): str +### @Uri:encode_component(text: str): str text をURI構成要素としてエンコードした文字列を返します。以下の文字はエンコードされません。 `A-Z a-z 0-9 - _ . ! ~ * ' ( )` -### @Uri:decode_uri(encoded_uri: str): str +### @Uri:decode_full(encoded_uri: str): str encoded_uri をエンコードされたURIとしてデコードした文字列を返します。 -`Uri:encode_uri`でエンコードされないエスケープシーケンスはデコードされません。 +`Uri:encode_full`でエンコードされないエスケープシーケンスはデコードされません。 -### @Uri:decode_uri_component(encoded_text: str): str +### @Uri:decode_component(encoded_text: str): str encoded_text をエンコードされたURI構成要素としてデコードした文字列を返します。 ## :: Arr diff --git a/src/interpreter/lib/std.ts b/src/interpreter/lib/std.ts index df46d6f5..81d72d42 100644 --- a/src/interpreter/lib/std.ts +++ b/src/interpreter/lib/std.ts @@ -501,22 +501,22 @@ export const std: Record = { //#endregion //#region Uri - 'Uri:encode_uri': FN_NATIVE(([v]) => { + 'Uri:encode_full': FN_NATIVE(([v]) => { assertString(v); return STR(encodeURI(v.value)); }), - 'Uri:encode_uri_component': FN_NATIVE(([v]) => { + 'Uri:encode_component': FN_NATIVE(([v]) => { assertString(v); return STR(encodeURIComponent(v.value)); }), - 'Uri:decode_uri': FN_NATIVE(([v]) => { + 'Uri:decode_full': FN_NATIVE(([v]) => { assertString(v); return STR(decodeURI(v.value)); }), - 'Uri:decode_uri_component': FN_NATIVE(([v]) => { + 'Uri:decode_component': FN_NATIVE(([v]) => { assertString(v); return STR(decodeURIComponent(v.value)); }), diff --git a/test/index.ts b/test/index.ts index a6fb2888..3a1befeb 100644 --- a/test/index.ts +++ b/test/index.ts @@ -3060,30 +3060,30 @@ describe('std', () => { }); describe('Uri', () => { - test.concurrent('encode_uri', async () => { + test.concurrent('encode_full', async () => { const res = await exe(` - <: Uri:encode_uri("https://example.com/?q=あいちゃん") + <: Uri:encode_full("https://example.com/?q=あいちゃん") `); eq(res, STR('https://example.com/?q=%E3%81%82%E3%81%84%E3%81%A1%E3%82%83%E3%82%93')); }); - test.concurrent('encode_uri_component', async () => { + test.concurrent('encode_component', async () => { const res = await exe(` - <: Uri:encode_uri_component("https://example.com/?q=あいちゃん") + <: Uri:encode_component("https://example.com/?q=あいちゃん") `); eq(res, STR('https%3A%2F%2Fexample.com%2F%3Fq%3D%E3%81%82%E3%81%84%E3%81%A1%E3%82%83%E3%82%93')); }); - test.concurrent('decode_uri', async () => { + test.concurrent('decode_full', async () => { const res = await exe(` - <: Uri:decode_uri("https%3A%2F%2Fexample.com%2F%3Fq%3D%E3%81%82%E3%81%84%E3%81%A1%E3%82%83%E3%82%93") + <: Uri:decode_full("https%3A%2F%2Fexample.com%2F%3Fq%3D%E3%81%82%E3%81%84%E3%81%A1%E3%82%83%E3%82%93") `); eq(res, STR('https%3A%2F%2Fexample.com%2F%3Fq%3Dあいちゃん')); }); - test.concurrent('decode_uri_component', async () => { + test.concurrent('decode_component', async () => { const res = await exe(` - <: Uri:decode_uri_component("https%3A%2F%2Fexample.com%2F%3Fq%3D%E3%81%82%E3%81%84%E3%81%A1%E3%82%83%E3%82%93") + <: Uri:decode_component("https%3A%2F%2Fexample.com%2F%3Fq%3D%E3%81%82%E3%81%84%E3%81%A1%E3%82%83%E3%82%93") `); eq(res, STR('https://example.com/?q=あいちゃん')); }); From f7face7911baad21e7391f95e50d8e40f9071359 Mon Sep 17 00:00:00 2001 From: salano_ym <53254905+salano-ym@users.noreply.github.com> Date: Sun, 31 Mar 2024 15:41:45 +0000 Subject: [PATCH 10/10] =?UTF-8?q?doc=E3=82=92=E4=BF=AE=E6=AD=A3(Uri:decode?= =?UTF-8?q?=5Ffull)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/std.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/std.md b/docs/std.md index efad9a3a..536e3112 100644 --- a/docs/std.md +++ b/docs/std.md @@ -142,7 +142,8 @@ text をURI構成要素としてエンコードした文字列を返します。 ### @Uri:decode_full(encoded_uri: str): str encoded_uri をエンコードされたURIとしてデコードした文字列を返します。 -`Uri:encode_full`でエンコードされないエスケープシーケンスはデコードされません。 +以下の文字に対応するエスケープシーケンスはデコードされません。 +`; , / ? : @ & = + $ #` ### @Uri:decode_component(encoded_text: str): str encoded_text をエンコードされたURI構成要素としてデコードした文字列を返します。