asan13

Untitled

Jul 22nd, 2017
558
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import std.stdio;
  2. import std.string;
  3. import std.conv;
  4. import std.regex;
  5.  
  6. string text = "#Header
  7. my header text
  8.  
  9. ##SubHeader
  10. my sub header text
  11.  
  12. ###Sub3Header
  13. my sub 3 text
  14.  
  15. ###Sub31Header
  16. my sub 3 text
  17.  
  18. #Header21
  19. my header2 text
  20.  
  21. ##SubHeader21
  22. my header2 text
  23.  
  24. ###SubHeader22
  25. my header3 text
  26. ";
  27.  
  28. int main(string[] args)
  29. {
  30.     auto re = ctRegex!(`^(#+).+?$.+?(?:(?=^#)|$(?!.))`, "ms");
  31.  
  32.     int[] nums;
  33.     foreach (m; text.matchAll(re))
  34.     {
  35.         auto len = m[1].length;
  36.  
  37.         while (nums.length && nums[$ - 1] >= len)
  38.         {
  39.             writeln("</div ", nums[$ - 1], ">");
  40.             nums = nums[0..$ - 1];
  41.         }
  42.  
  43.         nums ~= len.to!int;
  44.  
  45.         writeln("<div ", len, ">");
  46.         writeln(m[0]);
  47.     }
  48.  
  49.     foreach_reverse (len; nums)
  50.     {
  51.         writeln("</div ", len, ">");
  52.     }
  53.  
  54.     return 0;
  55. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×