home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _0381b3a4f964f5fab40b24ab7f0a2f88 < prev    next >
Text File  |  2000-03-23  |  5KB  |  119 lines

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>charnames - define character names for C<\N{named}> string literal escape.</TITLE>
  5. <LINK REL="stylesheet" HREF="../Active.css" TYPE="text/css">
  6. <LINK REV="made" HREF="mailto:">
  7. </HEAD>
  8.  
  9. <BODY>
  10. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  11. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  12. <STRONG><P CLASS=block> charnames - define character names for C<\N{named}> string literal escape.</P></STRONG>
  13. </TD></TR>
  14. </TABLE>
  15.  
  16. <A NAME="__index__"></A>
  17. <!-- INDEX BEGIN -->
  18.  
  19. <UL>
  20.  
  21.     <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
  22.  
  23.     <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
  24.     <LI><A HREF="#description">DESCRIPTION</A></LI>
  25.     <LI><A HREF="#custom translators">CUSTOM TRANSLATORS</A></LI>
  26.     <LI><A HREF="#bugs">BUGS</A></LI>
  27. </UL>
  28. <!-- INDEX END -->
  29.  
  30. <HR>
  31. <P>
  32. <H1><A NAME="name">NAME</A></H1>
  33. <P>charnames - define character names for <CODE>\N{named}</CODE> string literal escape.</P>
  34. <P>
  35. <HR>
  36. <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
  37. <UL>
  38. <LI>Linux</LI>
  39. <LI>Solaris</LI>
  40. <LI>Windows</LI>
  41. </UL>
  42. <HR>
  43. <H1><A NAME="synopsis">SYNOPSIS</A></H1>
  44. <PRE>
  45.   use charnames ':full';
  46.   print "\N{GREEK SMALL LETTER SIGMA} is called sigma.\n";</PRE>
  47. <PRE>
  48.   use charnames ':short';
  49.   print "\N{greek:Sigma} is an upper-case sigma.\n";</PRE>
  50. <PRE>
  51.   use charnames qw(cyrillic greek);
  52.   print "\N{sigma} is Greek sigma, and \N{be} is Cyrillic b.\n";</PRE>
  53. <P>
  54. <HR>
  55. <H1><A NAME="description">DESCRIPTION</A></H1>
  56. <P>Pragma <CODE>use charnames</CODE> supports arguments <CODE>:full</CODE>, <CODE>:short</CODE> and
  57. script names.  If <CODE>:full</CODE> is present, for expansion of
  58. <CODE>\N{CHARNAME}}</CODE> string <CODE>CHARNAME</CODE> is first looked in the list of
  59. standard Unicode names of chars.  If <CODE>:short</CODE> is present, and
  60. <CODE>CHARNAME</CODE> has the form <CODE>SCRIPT:CNAME</CODE>, then <CODE>CNAME</CODE> is looked up
  61. as a letter in script <CODE>SCRIPT</CODE>.  If pragma <CODE>use charnames</CODE> is used
  62. with script name arguments, then for <CODE>\N{CHARNAME}}</CODE> the name
  63. <CODE>CHARNAME</CODE> is looked up as a letter in the given scripts (in the
  64. specified order).</P>
  65. <P>For lookup of <CODE>CHARNAME</CODE> inside a given script <CODE>SCRIPTNAME</CODE>
  66. this pragma looks for the names</P>
  67. <PRE>
  68.   SCRIPTNAME CAPITAL LETTER CHARNAME
  69.   SCRIPTNAME SMALL LETTER CHARNAME
  70.   SCRIPTNAME LETTER CHARNAME</PRE>
  71. <P>in the table of standard Unicode names.  If <CODE>CHARNAME</CODE> is lowercase,
  72. then the <CODE>CAPITAL</CODE> variant is ignored, otherwise the <CODE>SMALL</CODE> variant is
  73. ignored.</P>
  74. <P>
  75. <HR>
  76. <H1><A NAME="custom translators">CUSTOM TRANSLATORS</A></H1>
  77. <P>The mechanism of translation of <CODE>\N{...}</CODE> escapes is general and not
  78. hardwired into <EM>charnames.pm</EM>.  A module can install custom
  79. translations (inside the scope which <A HREF="../lib/Pod/perlfunc.html#item_use"><CODE>use</CODE></A>s the module) with the
  80. following magic incantation:</P>
  81. <PRE>
  82.     use charnames ();           # for $charnames::hint_bits
  83.     sub import {
  84.         shift;
  85.         $^H |= $charnames::hint_bits;
  86.         $^H{charnames} = \&translator;
  87.     }</PRE>
  88. <P>Here <CODE>translator()</CODE> is a subroutine which takes <CODE>CHARNAME</CODE> as an
  89. argument, and returns text to insert into the string instead of the
  90. <CODE>\N{CHARNAME}</CODE> escape.  Since the text to insert should be different
  91. in <CODE>bytes</CODE> mode and out of it, the function should check the current
  92. state of <CODE>bytes</CODE>-flag as in:</P>
  93. <PRE>
  94.     use bytes ();                       # for $bytes::hint_bits
  95.     sub translator {
  96.         if ($^H & $bytes::hint_bits) {
  97.             return bytes_translator(@_);
  98.         }
  99.         else {
  100.             return utf8_translator(@_);
  101.         }
  102.     }</PRE>
  103. <P>
  104. <HR>
  105. <H1><A NAME="bugs">BUGS</A></H1>
  106. <P>Since evaluation of the translation function happens in a middle of
  107. compilation (of a string literal), the translation function should not
  108. do any <A HREF="../lib/Pod/perlfunc.html#item_eval"><CODE>eval</CODE></A>s or <A HREF="../lib/Pod/perlfunc.html#item_require"><CODE>require</CODE></A>s.  This restriction should be lifted in
  109. a future version of Perl.</P>
  110. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  111. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  112. <STRONG><P CLASS=block> charnames - define character names for C<\N{named}> string literal escape.</P></STRONG>
  113. </TD></TR>
  114. </TABLE>
  115.  
  116. </BODY>
  117.  
  118. </HTML>
  119.