Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editorconfig added #13

Merged
merged 3 commits into from
Jan 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
indent_style = space
indent_size = 4
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.yml]
indent_style = space
indent_size = 2
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.sublime-project
*.sublime-workspace
/nbproject/private/
.idea
/nbproject/private/
vendor
37 changes: 18 additions & 19 deletions src/Cocur/Slugify/Slugify.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
/**
* The MIT License (MIT)
* Copyright (c) 2012 Florian Eckerstorfer
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -43,10 +43,10 @@ class Slugify {
* taken, mixed and modified from:
* https://github.com/laravel/laravel/blob/master/application/config/strings.php
* https://github.com/sleepyboy/slug/blob/master/slug.php
*
* this is modified and will translit german umlauts to ae,etc and not simply to a.
*
* @var array
*
* this is modified and will translit german umlauts to ae,etc and not simply to a.
*
* @var array
*/
private static $ascii = array(
'/º|°/' => 0,
Expand Down Expand Up @@ -127,8 +127,8 @@ class Slugify {

/**
* possible slugify methods
*
* @var iconv|array
*
* @var iconv|array
*/
protected $mode = Slugify::MODEICONV;

Expand All @@ -150,6 +150,9 @@ public static function create($mode = null) {
* @return string Slug
*/
public function slugify($string, $separator = '-', $emptyValue = null) {
if (empty($string)) {
return '';
}

$string = preg_replace('/
[\x09\x0A\x0D\x20-\x7E] # ASCII
Expand All @@ -168,32 +171,28 @@ public function slugify($string, $separator = '-', $emptyValue = null) {
} else {
$string = $this->translitByArray($string);
}

// replace non letter or digits by seperator
$string = preg_replace('#[^\\pL\d]+#u', $separator, $string);
// trim
$string = trim($string, $separator);

// lowercase
$string = (defined('MB_CASE_LOWER')) ? mb_strtolower($string) : strtolower($string);

// remove unwanted characters
$string = preg_replace('#[^-\w]+#', '', $string);

if ($string === '') {
return $emptyValue ?: 'n' . $separator . 'a';
}

return $string;
}

/**
* taken form doctrine project
* needs locale to be set for country specific transliteration:
* needs locale to be set for country specific transliteration:
* setlocale(LC_ALL, 'de_DE.utf8','de_DE');
*
*
* caution: iconv doesnt work on all system, then use translitByArray
*
*
* @param type $text
* @return string
*/
Expand All @@ -203,7 +202,7 @@ public static function translitByIconv($text) {

/**
* transliterate a string with a array map
*
*
* @param string $title
* @return string
*/
Expand Down