X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=code_perl%2FMaasha%2FCommon.pm;h=079587ba4eb013f0b3d9f5179edb3efc4c204d24;hb=2f10201d21af91034ac31a45177de90d4ccef43b;hp=9f4170c01dd6d2769159d6f86b5c40edea69d769;hpb=a243213e6e37774b4363374706405070527e9826;p=biopieces.git diff --git a/code_perl/Maasha/Common.pm b/code_perl/Maasha/Common.pm index 9f4170c..079587b 100644 --- a/code_perl/Maasha/Common.pm +++ b/code_perl/Maasha/Common.pm @@ -29,6 +29,7 @@ package Maasha::Common; # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +use warnings; use strict; use Carp; use Data::Dumper; @@ -117,6 +118,30 @@ int match_m( char *str, char *substr, size_t str_len, size_t substr_len, size_t } +void str_analyze_C( const char *string ) +{ + /* Martin A. Hansen, July 2009 */ + + /* Scans a string incrementing the char count in an array. */ + + int count[ 256 ] = { 0 }; /* Integer array spanning the ASCII alphabet */ + int i; + + for ( i = 0; i < strlen( string ); i++ ) { + count[ ( int ) string[ i ] ]++; + } + + Inline_Stack_Vars; + Inline_Stack_Reset; + + for ( i = 0; i < 256; i++ ) { + Inline_Stack_Push( sv_2mortal( newSViv( count[ i ] ) ) ); + } + + Inline_Stack_Done; +} + + END_C @@ -155,7 +180,7 @@ sub error $file_max = length "File"; $line_max = length "Line"; - if ( $line =~ /^ at (.+) line (\d+)$/ ) + if ( $line =~ /^ at (.+) line (\d+)\.?$/ ) { $file = $1; $line_no = $2; @@ -696,6 +721,29 @@ sub wrap_line } +sub str_analyze +{ + # Martin A. Hansen, July 2009. + + # Analyzes the string composition of a given string. + + my ( $str, # string to analyze + ) = @_; + + # Returns hash + + my ( @composition, %hash, $i ); + + @composition = Maasha::Common::str_analyze_C( $str ); + + for ( $i = 32; $i <= 126; $i++ ) { # Only include printable chars + $hash{ chr $i } = $composition[ $i ] + } + + return wantarray ? %hash : \%hash; +} + + # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 1;