{"id":6669,"date":"2022-12-20T19:33:22","date_gmt":"2022-12-20T22:33:22","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/iconv-man3\/"},"modified":"2022-12-20T19:33:22","modified_gmt":"2022-12-20T22:33:22","slug":"iconv-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/iconv-man3\/","title":{"rendered":"Iconv (man3)"},"content":{"rendered":"<h1 align=\"center\">Iconv<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#ERRORS\">ERRORS<\/a><br \/> <a href=\"#NOTES\">NOTES<\/a><br \/> <a href=\"#AUTHOR\">AUTHOR<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Text::Iconv \u2212 Perl interface to iconv() codeset conversion function<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">use Text::Iconv; <br \/> $converter = Text::Iconv\u2212>new(&#8220;fromcode&#8221;, &#8220;tocode&#8221;); <br \/> $converted = $converter\u2212>convert(&#8220;Text to convert&#8221;);<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>Text::Iconv<\/b> module provides a Perl interface to the <b>iconv()<\/b> function as defined by the Single <small>UNIX<\/small> Specification.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>convert()<\/b> method converts the encoding of characters in the input string from the <i>fromcode<\/i> codeset to the <i>tocode<\/i> codeset, and returns the result.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Settings of <i>fromcode<\/i> and <i>tocode<\/i> and their permitted combinations are implementation-dependent. Valid values are specified in the system documentation; the <b>iconv<\/b>(1) utility should also provide a <b>\u2212l<\/b> option that lists all supported codesets.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Utility methods <br \/> Text::Iconv<\/b> objects also provide the following methods:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>retval()<\/b> returns the return value of the underlying <b>iconv()<\/b> function for the last conversion; according to the Single <small>UNIX<\/small> Specification, this value indicates &#8220;the number of non-identical conversions performed.&#8221; Note, however, that iconv implementations vary widely in the interpretation of this specification.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This method can be called after calling <b>convert()<\/b>, e.g.:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">$result = $converter\u2212>convert(&#8220;lorem ipsum dolor sit amet&#8221;); <br \/> $retval = $converter\u2212>retval;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">When called before the first call to <b>convert()<\/b>, or if an error occured during the conversion, <b>retval()<\/b> returns <b>undef<\/b>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>get_attr()<\/b>: This method is only available with <small>GNU<\/small> libiconv, otherwise it throws an exception. The <b>get_attr()<\/b> method allows you to query various attributes which influence the behavior of <b>convert()<\/b>. The currently supported attributes are <i>trivialp<\/i>, <i>transliterate<\/i>, and <i>discard_ilseq<\/i>, e.g.:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">$state = $converter\u2212>get_attr(&#8220;transliterate&#8221;);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">See <b>iconvctl<\/b>(3) for details. To ensure portability to other iconv implementations you should first check for the availability of this method using <b>eval {}<\/b>, e.g.:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">eval { $conv\u2212>get_attr(&#8220;trivialp&#8221;) }; <br \/> if ($@) <br \/> { <br \/> # get_attr() is not available <br \/> } <br \/> else <br \/> { <br \/> # get_attr() is available <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This method should be considered experimental.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>set_attr()<\/b>: This method is only available with <small>GNU<\/small> libiconv, otherwise it throws an exception. The <b>set_attr()<\/b> method allows you to set various attributes which influence the behavior of <b>convert()<\/b>. The currently supported attributes are <i>transliterate<\/i> and <i>discard_ilseq<\/i>, e.g.:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">$state = $converter\u2212>set_attr(&#8220;transliterate&#8221;);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">See <b>iconvctl<\/b>(3) for details. To ensure portability to other iconv implementations you should first check for the availability of this method using <b>eval {}<\/b>, cf. the description of <b>set_attr()<\/b> above.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This method should be considered experimental.<\/p>\n<h2>ERRORS <a name=\"ERRORS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">If the conversion can\u2019t be initialized an exception is raised (using <b>croak()<\/b>).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Handling of conversion errors<\/b> <i><br \/> Text::Iconv<\/i> provides a class attribute <b>raise_error<\/b> and a corresponding class method for setting and getting its value. The handling of errors during conversion depends on the setting of this attribute. If <b>raise_error<\/b> is set to a true value, an exception is raised; otherwise, the <b>convert()<\/b> method only returns <b>undef<\/b>. By default <b>raise_error<\/b> is false. Example usage:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Text::Iconv\u2212>raise_error(1); # Conversion errors raise exceptions <br \/> Text::Iconv\u2212>raise_error(0); # Conversion errors return undef <br \/> $a = Text::Iconv\u2212>raise_error(); # Get current setting<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Per-object handling of conversion errors<\/b> <br \/> As an experimental feature, <i>Text::Iconv<\/i> also provides an instance attribute <b>raise_error<\/b> and a corresponding method for setting and getting its value. If <b>raise_error<\/b> is <b>undef<\/b>, the class-wide settings apply. If <b>raise_error<\/b> is 1 or 0 (true or false), the object settings override the class-wide settings.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Consult <b>iconv<\/b>(3) for details on errors that might occur.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Conversion of undef<\/b> <br \/> Converting <b>undef<\/b>, e.g.,<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">$converted = $converter\u2212>convert(undef);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">always returns <b>undef<\/b>. This is not considered an error.<\/p>\n<h2>NOTES <a name=\"NOTES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The supported codesets, their names, the supported conversions, and the quality of the conversions are all system-dependent.<\/p>\n<h2>AUTHOR <a name=\"AUTHOR\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Michael Piotrowski <mxp@dynalabs.de><\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>iconv<\/b>(1), <b>iconv<\/b>(3)<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  Text::Iconv \u2212 Perl interface to iconv() codeset conversion function <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3007,3048],"class_list":["post-6669","post","type-post","status-publish","format-standard","hentry","category-sin-categoria","tag-man3","tag-texticonv"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6669","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=6669"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6669\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=6669"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=6669"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=6669"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}