Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.3 KiB

  1. package bytes;
  2. our $VERSION = '1.02';
  3. $bytes::hint_bits = 0x00000008;
  4. sub import {
  5. $^H |= $bytes::hint_bits;
  6. }
  7. sub unimport {
  8. $^H &= ~$bytes::hint_bits;
  9. }
  10. sub AUTOLOAD {
  11. require "bytes_heavy.pl";
  12. goto &$AUTOLOAD if defined &$AUTOLOAD;
  13. require Carp;
  14. Carp::croak("Undefined subroutine $AUTOLOAD called");
  15. }
  16. sub length ($);
  17. sub chr ($);
  18. sub ord ($);
  19. sub substr ($$;$$);
  20. sub index ($$;$);
  21. sub rindex ($$;$);
  22. 1;
  23. __END__
  24. =head1 NAME
  25. bytes - Perl pragma to force byte semantics rather than character semantics
  26. =head1 SYNOPSIS
  27. use bytes;
  28. ... chr(...); # or bytes::chr
  29. ... index(...); # or bytes::index
  30. ... length(...); # or bytes::length
  31. ... ord(...); # or bytes::ord
  32. ... rindex(...); # or bytes::rindex
  33. ... substr(...); # or bytes::substr
  34. no bytes;
  35. =head1 DESCRIPTION
  36. The C<use bytes> pragma disables character semantics for the rest of the
  37. lexical scope in which it appears. C<no bytes> can be used to reverse
  38. the effect of C<use bytes> within the current lexical scope.
  39. Perl normally assumes character semantics in the presence of character
  40. data (i.e. data that has come from a source that has been marked as
  41. being of a particular character encoding). When C<use bytes> is in
  42. effect, the encoding is temporarily ignored, and each string is treated
  43. as a series of bytes.
  44. As an example, when Perl sees C<$x = chr(400)>, it encodes the character
  45. in UTF-8 and stores it in $x. Then it is marked as character data, so,
  46. for instance, C<length $x> returns C<1>. However, in the scope of the
  47. C<bytes> pragma, $x is treated as a series of bytes - the bytes that make
  48. up the UTF8 encoding - and C<length $x> returns C<2>:
  49. $x = chr(400);
  50. print "Length is ", length $x, "\n"; # "Length is 1"
  51. printf "Contents are %vd\n", $x; # "Contents are 400"
  52. {
  53. use bytes; # or "require bytes; bytes::length()"
  54. print "Length is ", length $x, "\n"; # "Length is 2"
  55. printf "Contents are %vd\n", $x; # "Contents are 198.144"
  56. }
  57. chr(), ord(), substr(), index() and rindex() behave similarly.
  58. For more on the implications and differences between character
  59. semantics and byte semantics, see L<perluniintro> and L<perlunicode>.
  60. =head1 LIMITATIONS
  61. bytes::substr() does not work as an lvalue().
  62. =head1 SEE ALSO
  63. L<perluniintro>, L<perlunicode>, L<utf8>
  64. =cut