void XMLWriter::writeTag() { if (_openTags.empty() || _openTags.back().written) return; Tag &tag = _openTags.back(); tag.written = true; _stream->writeString("<" + tag.name); for (std::list<Property>::const_iterator p = tag.properties.begin(); p != tag.properties.end(); ++p) _stream->writeString(" " + p->name + "=\"" + escape(p->value) + "\""); if (tag.empty) _stream->writeString("/"); _stream->writeString(">"); if (!tag.empty) { if (!tag.base64.empty()) { while (!tag.base64.empty()) { breakLine(); indent(_openTags.size()); _stream->writeString(tag.base64.front()); tag.base64.pop_front(); } breakLine(); } else _stream->writeString(escape(tag.contents)); } }
TEST(DocumentUtilTest, EnglishNextStringTest) { { std::vector<std::string> list(breakLine("abcde")); ASSERT_EQ(1, list.size()); } { std::vector<std::string> list(breakLine("abc de")); ASSERT_EQ(2, list.size()); } }
//-- moocow: modified version of "textMess" for float lists // this can be used with moocow's pd-string external // available at http://www.ling.uni-potsdam.de/~moocow/projects/pd/#externs // it works like this: a string is represented as a list of ASCII-values ///////////////////////////////////////////////////////// // stringMess // ///////////////////////////////////////////////////////// void TextBase :: stringMess(int argc, t_atom *argv) { m_theText.clear(); if ( argc < 1 ) { return; } int i; wstring line = L""; for (i = 0; i < argc; i++) { int v=atom_getint(argv+i); /* * i experienced crashes in FTGL with indices>65535; * since TrueType fonts cannot hold more than 65536 entries * we just clamp it... * note: at least wikipedia claims that TTF can only hold 2^16 glyphs * i have seen ttf-fonts with (seemingly) more */ if(v<0||v>65535) { verbose(1, "invalid character %d: using ' ' instead", v); v=32; } line += static_cast<wchar_t>(v); } //line += L'\0'; breakLine(line); }
void justify(QStringList& text, int textWidth) { for (int i = 0; i < text.length(); ++i) { int length = text[i].length(); // Разбить строку. if (length > textWidth) { QString after; breakLine(text[i], after, textWidth); // Если строка не последняя, вставить часть после переноса в // начало следующей строки. if (i != text.length() - 1) { text[i + 1] = after + ' ' + text[i + 1]; } else { text << after; } } // Удлинить только не первую и не последнюю строку. else if (text.length() != 1 && (text.length() == 1 || i != text.length() - 1)) { fillSpaces(text[i], textWidth); } } }
TEST(DocumentUtilTest, JapaneseNextStringTest) { { std::vector<std::string> list(breakLine("あいう")); ASSERT_EQ(3, list.size()); } { std::vector<std::string> list(breakLine("あ")); ASSERT_EQ(1, list.size()); } { std::vector<std::string> list(breakLine("あ。")); ASSERT_EQ(1, list.size()); } { std::vector<std::string> list(breakLine("あ。いう。")); ASSERT_EQ(3, list.size()); } }
size_t putchar(char c) { switch (c) { case '\n': breakLine(); return 0; case '\b': backSpace(); return 0; case '\t': tabulate(); return 0; default: return putc(c, STDOUT); break; } }
void TextBase :: textMess(int argc, t_atom *argv) { m_theText.clear(); if ( argc < 1 ) { return; } wstring line = L""; int i=0; // convert the atom-list into 1 string for (i = 0; i < argc; ++i) { string newtext; if (A_FLOAT == argv[i].a_type) { char str[MAXPDSTRING]; char*sp=str; atom_string(&argv[i], str, MAXPDSTRING); while(*sp) { unsigned char c=*sp++; line+=c; } } else { const char*sp=atom_getsymbol(&argv[i])->s_name; try { std::wstring ws=gem::string::toWstring(sp); line+=ws; } catch (int i) { i=0; while(*sp) { unsigned char c=*sp++; line+=c; } } } if(argc-1>i) { line += L' '; } } breakLine(line); }
int main(int argc, char * argv[], char **envp) { //The following two functions catch and process the interrupt and stop signals //AKA signals sent by the Ctrl-C and Ctrl-Z commands if (signal(SIGINT,signal_catcher)==SIG_ERR) { perror("Sigset cannot set SIGINT"); exit(SIGINT); } if (signal(SIGTSTP, signal_catcher)==SIG_ERR) { perror("Sigset can not set SIGTSTP"); exit(SIGTSTP); } //Declaring and initializing variables to be used later initHistory(); initAlias(); int this_input = 0; char * input = (char *) malloc(sizeof(char)*64); strcpy (input, "noexit"); char *shellname = (char *) malloc(sizeof(char)*32); strcpy (shellname, "myshell"); setShellName(shellname); printf ("[%s]%% ", shellname); input = getLine(input, 100); //Making sure the program does not crash if the input simply the return key while (strcmp(input,"\0") == 0) { printf ("[%s]%% ", shellname); input = getLine(input, 100); } setHistory(input); breakLine (input); this_input = whichInput(); char ** argrv = getargrv(); int argrc = getargrc(); int loop = 1; while (loop != 0) { //Loop and process commands until the exist command is entered if(this_input==4) { if(strcmp(argrv[argrc-1], "&")==0) { //printf("Before forking PID:%d\n", getpid()); int pid = fork(); if(pid==0) { //sleep(2); //putting a delay in to emphasize background process //printf("\nchild PID: %d\n", getpid()); decrargrc(); list(); //printf("\nIn the child process - ended.\n\n"); return 0; } else { //printf("PPID:%d\n", getpid()); //printf("In the parent process.\n"); printf("%s process running in background", argrv[0]); } } else list(); } else if(this_input==3) { if(strcmp(argrv[argrc-1], "&")==0) { int pid = fork(); if(pid==0) { decrargrc(); pwd(); return 0; } else printf("%s process running in background", argrv[0]); } else pwd(); } else if(this_input==6) { if(strcmp(argrv[argrc-1], "&")==0) { int pid = fork(); if(pid==0) { decrargrc(); prompt(); shellname = getShellName(); return 0; } else printf("%s process running in background", argrv[0]); } else { prompt(); shellname = getShellName(); } } else if(this_input==2) { if(strcmp(argrv[argrc-1], "&")==0) { int pid = fork(); if(pid==0) { decrargrc(); dirChange(); return 0; } else printf("%s process running in background", argrv[0]); } else dirChange(); } else if(this_input==5) { if(strcmp(argrv[argrc-1], "&")==0) { int pid = fork(); if(pid==0) { decrargrc(); mypid(); return 0; } else printf("%s process running in background", argrv[0]); } else mypid(); } else if(this_input==1) { if (getargrc() == 1) { loop = 0; free (input); free (shellname); input = NULL; shellname = NULL; freeDynamicMem(); return 0; } else { printf("%s: Arguments not valid.", argrv[0]); } } else if(this_input==7) { if(strcmp(argrv[argrc-1], "&")==0) { int pid = fork(); if(pid==0) { decrargrc(); printHistory(); return 0; } else printf("%s process running in background", argrv[0]); } else printHistory(); } else if(this_input==8) { if(strcmp(argrv[argrc-1], "&")==0) { int pid = fork(); if(pid==0) { printf("\n***I've put a 3 second delay in to emphasize this background process\n"); sleep(3); //putting a delay in to emphasize background proces decrargrc(); printEnv(envp); return 0; } else printf("%s process running in background", argrv[0]); } else printEnv(envp); }else if(this_input==9) { if(strcmp(argrv[argrc-1], "&")==0) { int pid = fork(); if(pid==0) { decrargrc(); alias(); return 0; } else printf("%s process running in background", argrv[0]); } else alias(); }else if(this_input==10) { if(strcmp(argrv[argrc-1], "&")==0) { int pid = fork(); if(pid==0) { decrargrc(); murder(); return 0; } else printf("%s process running in background", argrv[0]); } else murder(); }else { nocmd(input); } printf ("\n[%s]%% ", shellname); input = getLine(input, 100); while (strcmp(input,"\0") == 0) { printf ("[%s]%% ", shellname); input = getLine(input, 100); } setHistory(input); breakLine (input); this_input = whichInput(); argrv = getargrv(); argrc = getargrc(); } return 0; }