#!/usr/bin/perl
package RVL::String;
##LICENSE##
use strict;
use warnings;
use HTML::StripTags qw(strip_tags);
use Class::Std::Utils;
{
sub getref {
my ($value) = shift;
unless (ref($value)) {
return getref(\$value);
}
return ref($value);
}
sub cleanHTMLTag {
my ($value, $notRemoveTags) = @_;
if (!$value) {
return ;
}
$notRemoveTags = '' if (!$notRemoveTags);
if (is_string($value)) {
$value = trim($value);
$value = strip_tags($value, $notRemoveTags);
} elsif (is_array($value)) {
my (@newArray);
foreach my $inArray( @{$value}) {
push(@newArray, cleanHTMLTag($inArray, $notRemoveTags));
}
@{$value} = @newArray;
} elsif (is_hash($value)) {
my (%newHash);
foreach my $key( keys %{$value}) {
$newHash{$key} = cleanHTMLTag(${$value}{$key}, $notRemoveTags);
}
%{$value} = %newHash;
} elsif (is_ref($value)) {
my ($newRef);
foreach my $key( keys %{$value}) {
$newRef->{$key} = cleanHTMLTag(${$value}->{$key}, $notRemoveTags);
}
%{$value} = $newRef;
}
return $value;
}
sub trim {
my ($value) = shift;
$value =~s/^[\s| ]+|[\s| ]+$//simx;
#$value =~s/(^\s+|\s+$)//simx;
return $value;
}
sub is_array {
my ($value) = shift;
if (getref($value) eq 'ARRAY') {
return 1;
} else {
return 0;
}
}
sub is_string {
my ($value) = shift;
if (getref($value) eq 'SCALAR') {
return 1;
} else {
return 0;
}
}
sub is_hash {
my ($value) = shift;
if (RVL::String::getref($value) eq 'HASH') {
return 1;
} else {
return 0;
}
}
sub is_ref {
my ($value) = shift;
if (RVL::String::getref($value) eq 'REF') {
return 1;
} else {
return 0;
}
}
=item
merge array with array = array
@array = merge(\@value1, \@value2);
merge hash with hash = hash
%hash = merge(\@value1, \@value2);
merge ref with ref = ref
$ref = merge($value1, $value2);
merge any with ref = ref
$ref = merge(@value1 or @value1 or $value1, $value2);
merge ref with any = ref
=cut
sub merge{
my ($value1, $value2) = @_;
if (is_string($value1) || is_string($value2)) {
#RVL::raiseError("Cannot merge string", 0, 1, __CONSTANT__::RVL_ERROR_NOFILE);
} elsif (is_array($value1) && is_array($value2)) {
return (@{$value1}, @{$value2});
} elsif (is_hash($value1) && is_hash($value2)) {
my ($resuft) = $value1;
foreach (keys %{$value2}) {
$resuft->{$_} = $value2->{$_};
}
return $resuft;
} elsif (is_ref($value1) && is_ref($value2)) {
my ($resuft) = ${$value1};
foreach (keys %{$value2}) {
$resuft->{$_} = $value2->{$_};
}
return $resuft;
}
}
sub array_map{
my ($callback) = shift;
my (@arr) = @_;
my (@new) = eval("RVL::String::$callback(\@arr);");
return @new;
}
sub lc{
my (@arr1) = @_;
my (@new);
foreach (@arr1) {
push(@new, lc($_));
}
return @new;
}
sub array_search{
my ($search) = shift;
return '' if !defined $search;
my (@arr) = @_;
my ($count) = 0;
foreach (@arr) {
if ($_ eq $search) {
return $count;
}
$count++;
}
return '';
}
sub translate {
my ($key, $filter, $aParams) = @_;
}
=item
=cut
sub unique_array(@) {
my %seen = ();
grep { not $seen{$_}++ } @_;
}
sub in_array {
my ($arr,$search_for) = @_;
return 1 if (grep {$search_for eq $_} @$arr);
return 0;
}
}
1;
Copyright 2K16 - 2K18 Indonesian Hacker Rulez