Skip to content

Instantly share code, notes, and snippets.

@sang4lv
Last active December 21, 2015 04:29
Show Gist options
  • Save sang4lv/6250170 to your computer and use it in GitHub Desktop.
Save sang4lv/6250170 to your computer and use it in GitHub Desktop.
Para not available inside do...while
function find( mode, string, begin, end ) {
console.log("the input " + string);
var startIndex = string.indexOf(begin);
var endIndex = string.indexOf(end, startIndex + 1);
if( startIndex === -1 && endIndex === -1 ) return "";
var result = ( mode === "include" ) ?
string.slice( startIndex + begin.length, endIndex ) :
string.slice( 0, startIndex ) + string.slice( endIndex + end.length );
console.log("the return " + result);
return result;
}
function splitParagraph(para) {
var result = {
content: "",
footnote: [],
emphasize: [],
};
var temp = "";
do {
temp = find( "include", para, "*", "*" );
para = find( "exclude", para, "*", "*" );
if(temp !== "") result.emphasize.push(temp);
} while( temp !== "" );
do {
temp = find( "include", para, "{", "}" );
para = find( "exclude", para, "{", "}" );
if(temp !== "") result.footnote.push(temp);
} while( temp !== "" );
result.content = para;
return result;
}
var str = "They are solid, but when they must *change*, violence must be done to them{Referring to the fact that structure tends to put restrictions on the evolution of a program.}.";
console.log( splitParagraph(str) );
/*
Result
the input They are solid, but when they must *change*, violence must be done to them{Referring to the fact that structure tends to put restrictions on the evolution of a program.}.
the return change
the input They are solid, but when they must *change*, violence must be done to them{Referring to the fact that structure tends to put restrictions on the evolution of a program.}.
the return They are solid, but when they must , violence must be done to them{Referring to the fact that structure tends to put restrictions on the evolution of a program.}.
the input They are solid, but when they must , violence must be done to them{Referring to the fact that structure tends to put restrictions on the evolution of a program.}.
the input They are solid, but when they must , violence must be done to them{Referring to the fact that structure tends to put restrictions on the evolution of a program.}.
the input
the input
{
content: "",
footnote: [],
emphasized: ["change"]
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment