관리-도구
편집 파일: unpack-i.yaml
--- !ruby/object:RI::MethodDescription aliases: [] block_params: comment: - !ruby/struct:SM::Flow::P body: Decodes <em>str</em> (which may contain binary data) according to the format string, returning an array of each value extracted. The format string consists of a sequence of single-character directives, summarized in the table at the end of this entry. Each directive may be followed by a number, indicating the number of times to repeat with this directive. An asterisk (``<tt>*</tt>'') will use up all remaining elements. The directives <tt>sSiIlL</tt> may each be followed by an underscore (``<tt>_</tt>'') to use the underlying platform's native size for the specified type; otherwise, it uses a platform-independent consistent size. Spaces are ignored in the format string. See also <tt>Array#pack</tt>. - !ruby/struct:SM::Flow::VERB body: " "abc \\0\\0abc \\0\\0".unpack('A6Z6') #=> ["abc", "abc "]\n "abc \\0\\0".unpack('a3a3') #=> ["abc", " \\000\\000"]\n "abc \\0abc \\0".unpack('Z*Z*') #=> ["abc ", "abc "]\n "aa".unpack('b8B8') #=> ["10000110", "01100001"]\n "aaa".unpack('h2H2c') #=> ["16", "61", 97]\n "\\xfe\\xff\\xfe\\xff".unpack('sS') #=> [-2, 65534]\n "now=20is".unpack('M*') #=> ["now is"]\n "whole".unpack('xax2aX2aX1aX2a') #=> ["h", "e", "l", "l", "o"]\n" - !ruby/struct:SM::Flow::P body: This table summarizes the various formats and the Ruby classes returned by each. - !ruby/struct:SM::Flow::VERB body: " Format | Returns | Function\n -------+---------+-----------------------------------------\n A | String | with trailing nulls and spaces removed\n -------+---------+-----------------------------------------\n a | String | string\n -------+---------+-----------------------------------------\n B | String | extract bits from each character (msb first)\n -------+---------+-----------------------------------------\n b | String | extract bits from each character (lsb first)\n -------+---------+-----------------------------------------\n C | Fixnum | extract a character as an unsigned integer\n -------+---------+-----------------------------------------\n c | Fixnum | extract a character as an integer\n -------+---------+-----------------------------------------\n d,D | Float | treat sizeof(double) characters as\n | | a native double\n -------+---------+-----------------------------------------\n E | Float | treat sizeof(double) characters as\n | | a double in little-endian byte order\n -------+---------+-----------------------------------------\n e | Float | treat sizeof(float) characters as\n | | a float in little-endian byte order\n -------+---------+-----------------------------------------\n f,F | Float | treat sizeof(float) characters as\n | | a native float\n -------+---------+-----------------------------------------\n G | Float | treat sizeof(double) characters as\n | | a double in network byte order\n -------+---------+-----------------------------------------\n g | Float | treat sizeof(float) characters as a\n | | float in network byte order\n -------+---------+-----------------------------------------\n H | String | extract hex nibbles from each character\n | | (most significant first)\n -------+---------+-----------------------------------------\n h | String | extract hex nibbles from each character\n | | (least significant first)\n -------+---------+-----------------------------------------\n I | Integer | treat sizeof(int) (modified by _)\n | | successive characters as an unsigned\n | | native integer\n -------+---------+-----------------------------------------\n i | Integer | treat sizeof(int) (modified by _)\n | | successive characters as a signed\n | | native integer\n -------+---------+-----------------------------------------\n L | Integer | treat four (modified by _) successive\n | | characters as an unsigned native\n | | long integer\n -------+---------+-----------------------------------------\n l | Integer | treat four (modified by _) successive\n | | characters as a signed native\n | | long integer\n -------+---------+-----------------------------------------\n M | String | quoted-printable\n -------+---------+-----------------------------------------\n m | String | base64-encoded\n -------+---------+-----------------------------------------\n N | Integer | treat four characters as an unsigned\n | | long in network byte order\n -------+---------+-----------------------------------------\n n | Fixnum | treat two characters as an unsigned\n | | short in network byte order\n -------+---------+-----------------------------------------\n P | String | treat sizeof(char *) characters as a\n | | pointer, and return \\emph{len} characters\n | | from the referenced location\n -------+---------+-----------------------------------------\n p | String | treat sizeof(char *) characters as a\n | | pointer to a null-terminated string\n -------+---------+-----------------------------------------\n Q | Integer | treat 8 characters as an unsigned\n | | quad word (64 bits)\n -------+---------+-----------------------------------------\n q | Integer | treat 8 characters as a signed\n | | quad word (64 bits)\n -------+---------+-----------------------------------------\n S | Fixnum | treat two (different if _ used)\n | | successive characters as an unsigned\n | | short in native byte order\n -------+---------+-----------------------------------------\n s | Fixnum | Treat two (different if _ used)\n | | successive characters as a signed short\n | | in native byte order\n -------+---------+-----------------------------------------\n U | Integer | UTF-8 characters as unsigned integers\n -------+---------+-----------------------------------------\n u | String | UU-encoded\n -------+---------+-----------------------------------------\n V | Fixnum | treat four characters as an unsigned\n | | long in little-endian byte order\n -------+---------+-----------------------------------------\n v | Fixnum | treat two characters as an unsigned\n | | short in little-endian byte order\n -------+---------+-----------------------------------------\n w | Integer | BER-compressed integer (see Array.pack)\n -------+---------+-----------------------------------------\n X | --- | skip backward one character\n -------+---------+-----------------------------------------\n x | --- | skip forward one character\n -------+---------+-----------------------------------------\n Z | String | with trailing nulls removed\n | | upto first null with *\n -------+---------+-----------------------------------------\n @ | --- | skip to the offset given by the\n | | length argument\n -------+---------+-----------------------------------------\n" full_name: String#unpack is_singleton: false name: unpack params: | str.unpack(format) => anArray visibility: public