AmberDB
view release on metacpan or search on metacpan
lib/AmberDB/Base.pm view on Meta::CPAN
package AmberDB::Base;
use 5.016;
use warnings;
use Encode qw(is_utf8 encode decode);
use Carp qw(croak cluck);
use File::Spec;
use Fcntl qw(:DEFAULT :flock);
use Digest::SHA qw(sha256_hex);
use parent qw(AmberDB::Locale AmberDB::Array);
our $VERSION = '5.25.2';
my $CREATED = '2014-12-20';
# ------------------------------------------------
sub new {
my $class = shift;
my %args = ( ref $_[0] eq 'HASH' ) ? %{ $_[0] } : @_;
# Initialise the Language engine with the supplied language tag.
# SUPER::new is AmberDB::Locale::new â it handles locale loading.
my $self = $class->SUPER::new(%args);
return $self;
}
# ============================================================================
# STRING UTILITIES (Trim & Whitespace Normalization)
# ============================================================================
# $adb->trim_space($string, [$flatten])
# Strips leading/trailing whitespace and normalizes internal spaces/newlines.
# ---------------------------------------------------------------------
sub trim_space {
my ( $self, $string, $flatten ) = @_;
return '' unless defined $string && length $string;
$string =~ s/ / /g;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
$string =~ s/\r\n/\n/g;
if ($flatten) {
$string =~ s/[\r\n\t\s]+/ /g;
$string =~ s/ *([,;]) */$1/g;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
}
else {
$string =~ s/\n/\\n/g;
$string =~ s/\t/\\t/g;
$string =~ s/\s+/ /g;
$string =~ s/ *([,;]) */$1/g;
$string =~ s/ *\\n */\n/g;
$string =~ s/ *\\t */\t/g;
}
return $string;
}
# $data = $adb->set_charset($from, $to, $data);
# Converts between character encoding tables...
# ------------------------------------------------
sub set_charset {
my ( $self, $from, $to, $data ) = @_;
( $from && $to && $data ) or return;
return $data if ( $to eq "utf8" && utf8::is_utf8($data) );
return encode( $to, decode( $from, $data ) );
}
# Extracts search words from string...
# my %words = $self->get_words($string);
# my %words = $self->get_words($string, $write, $table);
# ------------------------------------------------
sub get_words {
my ( $self, $string, $action, $table ) = @_;
$string or return;
if ( ref($string) eq 'ARRAY' ) {
( run in 2.109 seconds using v1.01-cache-2.11-cpan-54e63673c56 )