Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. function parseTags(text) {
  2. var inTag,
  3. afterOpenTag,
  4. afterClosingTag,
  5. inUpperCase,
  6. inLowerCase,
  7. inMixCase,
  8. i,
  9. len,
  10. trueOrFalse,
  11. result = '',
  12. ;
  13.  
  14. for (i = 0, len = text.length; i < len; i += 1) {
  15. if (text[i] === '<') {
  16. inTag = true;
  17. afterOpenTag = true;
  18. }
  19.  
  20.  
  21. if(inTag && afterOpenTag && text[i] === '/'){
  22. afterClosingTag = true;
  23. afterOpenTag = false;
  24. }
  25.  
  26.  
  27. if (inTag && afterOpenTag && text[i] === 'u') {
  28. inUpperCase = true;
  29. afterOpenTag = false;
  30. }
  31. if (inTag && afterOpenTag && text[i] === 'l') {
  32. inLowerCase = true;
  33. afterOpenTag = false;
  34. }
  35. if (inTag && afterOpenTag && text[i] === 'm') {
  36. inMixCase = true;
  37. afterOpenTag = false;
  38. }
  39.  
  40.  
  41. if (inTag && afterClosingTag && text[i] === 'u') {
  42. inUpperCase = false;
  43. afterClosingTag = false;
  44. }
  45. if (inTag && afterClosingTag && text[i] === 'l') {
  46. inLowerCase = false;
  47. afterClosingTag = false;
  48. }
  49. if (inTag && afterClosingTag && text[i] === 'm') {
  50. inMixCase = false;
  51. afterClosingTag = false;
  52.  
  53. console.log("close mix " + inMixCase);
  54. }
  55.  
  56. if (!inTag && inUpperCase) {
  57. result += text[i].toUpperCase();
  58. }
  59. if (!inTag && inLowerCase) {
  60. result += text[i].toLowerCase();
  61. }
  62. if (!inTag && inMixCase) {
  63. console.log("in mix " + inMixCase);
  64. trueOrFalse = Math.round(Math.random());
  65. if (trueOrFalse) {
  66. result += text[i].toUpperCase();
  67. } else {
  68. result += text[i].toLowerCase();
  69. }
  70. }
  71.  
  72.  
  73.  
  74.  
  75. if (!inTag && !inLowerCase && !inUpperCase && !inMixCase) {
  76. result += text[i];
  77. }
  78.  
  79. if (text[i] === '>') {
  80. inTag = false;
  81. }
  82.  
  83. }
  84. return result;
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement