Skip to content

Instantly share code, notes, and snippets.

@mherger
Last active June 1, 2016 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mherger/0a966eb0222b7802d4b3b50b749e0a32 to your computer and use it in GitHub Desktop.
Save mherger/0a966eb0222b7802d4b3b50b749e0a32 to your computer and use it in GitHub Desktop.
diff --git a/Slim/Utils/Unicode.pm b/Slim/Utils/Unicode.pm
index 6321b8b..9dd802d 100644
--- a/Slim/Utils/Unicode.pm
+++ b/Slim/Utils/Unicode.pm
@@ -317,10 +317,30 @@
return 1 if $_[0] !~ /[^\x00-\x7F\xA0-\xFF]/;
return 0;
}
+=head2 looks_like_cp1251( $string )
+
+Returns true if the passed string is Windows-1251
+
+Returns false otherwise.
+
+=cut
+
+sub looks_like_cp1251 {
+ return 0 if looks_like_ascii($_[0]);
+
+ use bytes;
+
+ if ( hasEDD() ) {
+ my $charset = Encode::Detect::Detector::detect($_[0]);
+ return 1 if $charset && $charset =~ /1251/;
+ }
+ return 0;
+}
+
=head2 looks_like_cp1252( $string )
Returns true if the passed string is Windows-1252
Returns false otherwise.
@@ -459,10 +479,14 @@
} elsif (looks_like_utf8($string)) {
return 'utf8';
+ } elsif (looks_like_cp1251($string)) {
+
+ return 'cp1251';
+
} elsif (looks_like_latin1($string)) {
return 'iso-8859-1';
} elsif (looks_like_cp1252($string)) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment