Skip to content

Latest commit

 

History

History
143 lines (84 loc) · 4.63 KB

moyo_string.md

File metadata and controls

143 lines (84 loc) · 4.63 KB

Module moyo_string

文字列(整数値のリスト)に関する処理を集めたユーティリティモジュール.

Copyright (c) 2013-2014 DWANGO Co., Ltd. All Rights Reserved.

Data Types


encode_option() = print | {float_format, [float_format_option()]}

float_format_option() = {scientific, Decimals::0..249} | {decimals, Decimals::0..253} | compact

Function Index

format/2指定されたフォーマットの文字列を生成して返す.
is_ascii_string/1引数の値がASCII文字列であるかどうかを判定する.
is_iodata/1引数の値がiodataであるかどうかを判定する.
is_iolist/1引数の値がiolistであるかどうかを判定する.
to_string/1Equivalent to to_string(V, []).
to_string/2Erlangの項を文字列(数値のリスト)に、指定されたオプションに従って変換する.

Function Details

format/2


format(Format, Data) -> string()

指定されたフォーマットの文字列を生成して返す.

lists:flatten(io_lib:format(Format, Data))と同等.

is_ascii_string/1


is_ascii_string(Value::term()) -> boolean()

引数の値がASCII文字列であるかどうかを判定する

ASCII文字列とは 0 から 127 までのコード値の文字で構成されている文字列のこと

is_iodata/1


is_iodata(Value::term()) -> boolean()

引数の値がiodataであるかどうかを判定する

iodata()の型はbinary() | iolist().

is_iolist/1


is_iolist(Value::term()) -> boolean()

引数の値がiolistであるかどうかを判定する

iolist()の型は maybe_improper_list(byte() | binary() | iolist(), binary() | []).
See: http://www.erlang.org/doc/reference_manual/typespec.html

to_string/1

to_string(V) -> any()

Equivalent to to_string(V, []).

to_string/2


to_string(V::term(), Rest::[encode_option()]) -> string()

Erlangの項を文字列(数値のリスト)に、指定されたオプションに従って変換する

入力値が非負の数値リストの場合は、変換は行われずにそのまま返される。
ユニコード値のリストから、UTF-8のリストへ変換したい場合等は unicode モジュールを使用する必要がある。

入力値がタプルや深いリストならば print オプションを指定することで
io_lib:format/2 のフォーマット"~p"に従った表現で変換することができる。
デフォルト値は"~w"

入力値が浮動小数点数ならば float_to_list/2 で指定できるオプション
[{scientific, Decimals} | {decimals, Decimals} | compact]
を利用して変換方式を指定することができる。
{scientific, Decimals} と {decimals, Decimals} が同時に指定された場合は、最後に指定されたものが採用される。
例:

  > moyo_string:to_string(12.34, [{float_format, [{scientific, 6}]}]).
  "1.234000e+01"
  > moyo_string:to_string(12.34, [{float_format, [{decimals, 6}]}]).
  "12.340000"
  > moyo_string:to_string(12.34, [{float_format, [{decimals, 6}, compact]}]).
  "12.34"