C-Utility

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

-----------------------------------------------------------------------------

1. ABOUT

C::Utility - utilities for generating C programs

This module contains functions which assist in automatic generation of
C programs. For work with strings, "convert_to_c_string" converts a
string into a string with characters correctly escaped for use in a C
program. "convert_to_c_string_pc" does the same thing plus escaping
percent signs so that they may be used as format strings for
printf. "escape_string" escapes double quotes. "valid_c_variable"
checks whether a string is valid as a C variable. 

The module contains various line directive related
functions. "line_directive" prints a C line directive. "linein"
and "lineout" offer a preprocessor and postprocessor to add line
numbers to files made from templates.

-----------------------------------------------------------------------------

lib/C/Utility.pod  view on Meta::CPAN


This documents C::Utility version 0.012
corresponding to git commit L<23840f2d0676c73ceefdde8dff0967d1ff4eeecc|https://github.com/benkasminbullock/C-Utility/commit/23840f2d0676c73ceefdde8dff0967d1ff4eeecc> released on Sat Sep 1 11:00:14 2018 +0900.

=head1 DESCRIPTION

This module contains functions which assist in automatic generation of
C programs. For work with strings, L</convert_to_c_string> converts a
string into a string with characters correctly escaped for use in a C
program. L</convert_to_c_string_pc> does the same thing plus escaping
percent signs so that they may be used as format strings for
printf. L</escape_string> escapes double quotes. L</valid_c_variable>
checks whether a string is valid as a C variable. 

The module contains various line directive related
functions. L</line_directive> prints a C line directive. L</linein>
and L</lineout> offer a preprocessor and postprocessor to add line
numbers to files made from templates.

=head1 EXPORTS

lib/C/Utility.pod  view on Meta::CPAN

It also removes backslashes from before the @ symbol, so \@ is
transformed to @. Newlines within the input string are turned into
concatenated strings. Empty inputs are turned into a pair of double
quotes, C<"">.

=head2 convert_to_c_string_pc

    my $c_string = convert_to_c_string_pc ($string);     

This is similar to L</convert_to_c_string>, but it also converts the
percent character C<%> to a double percent, C<%%>. This is for
generating strings which may be used as C format strings without
generating an error because of embedded percent characters.

    
    use C::Utility 'convert_to_c_string_pc';
    my $string =<<'EOF';
    The quick "brown" fox\@farm
    jumped %over the lazy dog.
    EOF
    print convert_to_c_string_pc ($string);


t/C-Utility.t  view on Meta::CPAN

use C::Utility ':all';

my $in = <<EOF;
This is the " input string.
EOF

my $out = convert_to_c_string ($in);
#print "$out\n";
ok ($out eq '"This is the \" input string.\n"'."\n");

my $percent = 'This has a percent %';

my $out2 = convert_to_c_string_pc ($percent);

ok ($out2 eq '"This has a percent %%"');

# Local variables:
# mode: perl
# End:



( run in 0.384 second using v1.01-cache-2.11-cpan-709fd43a63f )