Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://baussprojects.comlu.com/projects.php#daweb
- /*
- * Inserts an attribute to a html tag with a specific id.
- */
- string insertAttribute(string html, string id, string attributeName, string attributeValue) {
- import std.algorithm : countUntil;
- import std.string : format;
- ptrdiff_t index = countUntil(html, format("id=\"%s\"", id));
- index += countUntil(html[index .. $], ">");
- string beforeStr = html[0 .. index];
- string n = beforeStr ~ " " ~ format("%s=\"%s\"", attributeName, attributeValue);
- return n ~ html[index .. $];
- }
- /**
- * Inserts html code into a specific html tag with a specific id.
- */
- string insertHtml(string html, string id, string insertHtml) {
- import std.algorithm : countUntil;
- import std.string : format;
- ptrdiff_t index = countUntil(html, format("id=\"%s\"", id));
- index += countUntil(html[index .. $], ">");
- string beforeStr = html[0 .. index + 1];
- string n = beforeStr ~ insertHtml ~ html[index + 1 .. $];
- return n;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement