How to resolve the algorithm Rosetta Code/Fix code tags step by step in the D programming language

Published on 12 May 2024 09:40 PM
#D

How to resolve the algorithm Rosetta Code/Fix code tags step by step in the D programming language

Table of Contents

Problem Statement

Fix Rosetta Code deprecated code tags, with these rules:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Rosetta Code/Fix code tags step by step in the D programming language

Source code in the d programming language

import std.stdio, std.regex, std.string, std.array;

immutable langs = "_div abap actionscript actionscript3 ada apache
applescript apt_sources asm asp autoit avisynth bash basic4gl bf
blitzbasic bnf boo c c_mac caddcl cadlisp cfdg cfm cil cobol cpp
cpp-qt csharp css d delphi diff dos dot eiffel email fortran
freebasic genero gettext glsl gml gnuplot groovy haskell hq9plus
html4strict idl ini inno intercal io java java5 javascript kixtart
klonec klonecpp latex lisp lolcode lotusformulas lotusscript
lscript lua m68k make matlab mirc modula3 mpasm mxml mysql nsis
objc ocaml ocaml-brief oobas oracle11 oracle8 pascal per perl php
php-brief pic16 pixelbender plsql povray powershell progress
prolog providex python qbasic rails reg robots ruby sas scala
scheme scilab sdlbasic smalltalk smarty sql tcl teraterm text
thinbasic tsql typoscript vb vbnet verilog vhdl vim visualfoxpro
visualprolog whitespace winbatch xml xorg_conf xpp z80".split;

string fixTags(string text) {
    static immutable slang = "/lang";
    static immutable code = "code";

    foreach (immutable lang; langs) {
        text = text.replace("<%s>".format(lang),
                            "<lang %s>".format(lang));
        text = text.replace("</%s>".format(lang),
                            "<%s>".format(slang));
    }

    return text.replace("<%s (.+?)>(.*?)</%s>"
                        .format(code, code).regex("g"),
                        "<lang $1>$2<%s>".format(slang));
}

void main() {
    ("lorem ipsum <c>some c code</c>dolor sit amet, <csharp>some " ~
    "csharp code</csharp> consectetur adipisicing elit, <code r>" ~
    " some r code </code>sed do eiusmod tempor incididunt")
    .fixTags
    .writeln;
}


  

You may also check:How to resolve the algorithm Magic squares of singly even order step by step in the D programming language
You may also check:How to resolve the algorithm Abbreviations, easy step by step in the Perl programming language
You may also check:How to resolve the algorithm Day of the week step by step in the ECL programming language
You may also check:How to resolve the algorithm Lucas-Lehmer test step by step in the PowerShell programming language
You may also check:How to resolve the algorithm Smith numbers step by step in the Miranda programming language