mirror of
https://github.com/discourse/discourse.git
synced 2025-03-25 09:45:51 +08:00
better split logic for names starting with capitols eg: ABBob should split to AB Bob
This commit is contained in:
parent
9977f3098c
commit
61d3e43744
@ -13,13 +13,29 @@ Discourse.Formatter = (function(){
|
|||||||
|
|
||||||
var firstPart = string.substr(0, maxLength);
|
var firstPart = string.substr(0, maxLength);
|
||||||
|
|
||||||
var betterSplit = firstPart.substr(1).search(/[^a-z]/);
|
// work backward to split stuff like ABPoop to AB Poop
|
||||||
if (betterSplit >= 0) {
|
var i;
|
||||||
var offset = 1;
|
for(i=firstPart.length-1;i>0;i--){
|
||||||
if(string[betterSplit+1] === "_") {
|
if(firstPart[i].match(/[A-Z]/)){
|
||||||
offset = 2;
|
break;
|
||||||
}
|
}
|
||||||
return string.substr(0, betterSplit + offset) + " " + string.substring(betterSplit + offset);
|
}
|
||||||
|
|
||||||
|
// work forwards to split stuff like ab111 to ab 111
|
||||||
|
if(i===0) {
|
||||||
|
for(i=1;i<firstPart.length;i++){
|
||||||
|
if(firstPart[i].match(/[^a-z]/)){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i > 0 && i < firstPart.length) {
|
||||||
|
var offset = 0;
|
||||||
|
if(string[i] === "_") {
|
||||||
|
offset = 1;
|
||||||
|
}
|
||||||
|
return string.substr(0, i + offset) + " " + string.substring(i + offset);
|
||||||
} else {
|
} else {
|
||||||
return firstPart + " " + string.substr(maxLength);
|
return firstPart + " " + string.substr(maxLength);
|
||||||
}
|
}
|
||||||
|
@ -199,5 +199,6 @@ test("breakUp", function(){
|
|||||||
equal(b("HeMans"), "He Mans");
|
equal(b("HeMans"), "He Mans");
|
||||||
equal(b("he_man"), "he_ man");
|
equal(b("he_man"), "he_ man");
|
||||||
equal(b("he11111"), "he 11111");
|
equal(b("he11111"), "he 11111");
|
||||||
|
equal(b("HRCBob"), "HRC Bob");
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user