Skip to content

Commit

Permalink
Strip any BOM from the string - so it's sorted correctly.
Browse files Browse the repository at this point in the history
Remove a bunch of unused functions.

Bug: 2311
git-svn-id: file:///home/awy/mirror/slim/trunk/server@4691 62299810-d8cb-41fd-93b7-d32162e5a4a4
  • Loading branch information
Dan Sully committed Oct 19, 2005
1 parent 2e7302c commit 267f05f
Showing 1 changed file with 8 additions and 63 deletions.
71 changes: 8 additions & 63 deletions Slim/Utils/Text.pm
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package Slim::Utils::Text;

use strict;
use Tie::Cache::LRU;

# $Id$

# SlimServer Copyright (c) 2001-2004 Sean Adams, Slim Devices Inc.
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License,
# version 2.

use strict;
use Tie::Cache::LRU;

use Slim::Utils::Unicode;

tie our %caseArticlesMemoize, 'Tie::Cache::LRU', 128;
tie our %sortCache, 'Tie::Cache::LRU', 128;

sub ignorePunct {
my $s = shift || return undef;
Expand All @@ -23,6 +24,9 @@ sub ignorePunct {
$s =~ s/^ +//o; # zap leading/trailing spaces.
$s =~ s/ +$//o;

# See bug: 2311
$s = Slim::Utils::Unicode::stripBOM($s);

$s = $orig if $s eq '';

return $s;
Expand Down Expand Up @@ -80,65 +84,6 @@ sub clearCaseArticleCache {
%caseArticlesMemoize = ();
}

sub sortIgnoringCase {
use locale;

# set up an array without case for sorting
my @nocase = map { ignoreCaseArticles($_) } @_;

# return the original array sliced by the sorted caseless array
return @_[sort {$nocase[$a] cmp $nocase[$b]} 0..$#_];
}

sub sortuniq {
use locale;

my %seen = ();
my @uniq = ();

for my $item (@_) {
if (defined($item) && ($item ne '') && !$seen{ignoreCaseArticles($item)}++) {
push(@uniq, $item);
}
}

return sort @uniq ;
}

# similar to above but ignore preceeding articles when sorting
sub sortuniq_ignore_articles {
use locale;

my %seen = ();
my @uniq = ();
my $articles = Slim::Utils::Prefs::get("ignoredarticles");

# allow a space seperated list in preferences (easier for humans to deal with)
$articles =~ s/\s+/|/g;

for my $item (@_) {
if (defined($item) && ($item ne '') && !$seen{ignoreCaseArticles($item)}++) {
push(@uniq, $item);
}
}

# set up array for sorting items without leading articles
my @noarts = map {
my $item = $_;
exists($sortCache{$item}) ? $item = $sortCache{$item} : $item =~ s/^($articles)\s+//i;
$item;
} @uniq;

# return the uniq array sliced by the sorted articleless array
return @uniq[sort {$noarts[$a] cmp $noarts[$b]} 0..$#uniq];
}

sub getSortName {
my $item = shift || return;

return exists($sortCache{ignoreCaseArticles($item)}) ? $sortCache{ignoreCaseArticles($item)} : $item;
}

1;

__END__
Expand Down

0 comments on commit 267f05f

Please sign in to comment.