Exemplo n.º 1
0
void Quoter::quoteFromFile( const QString& userFriendlyFilePath,
			    const QString& plainCode,
			    const QString& markedCode )
{
    silent = false;

    /*
      Split the source code into logical lines. Empty lines are
      treated specially. Before:

	  p->alpha();
	  p->beta();

	  p->gamma();


	  p->delta();

      After:

	  p->alpha();
	  p->beta();\n
	  p->gamma();\n\n
	  p->delta();

      Newlines are preserved because they affect codeLocation.
    */
    codeLocation = Location( userFriendlyFilePath );

    plainLines = splitLines(plainCode);
    markedLines = splitLines(markedCode);
    if (markedLines.count() != plainLines.count()) {
        codeLocation.warning(tr("Something is wrong with qdoc's handling of marked code"));
        markedLines = plainLines;
    }

    /*
      Squeeze blanks (cat -s).
    */
    QStringList::Iterator m = markedLines.begin();
    while ( m != markedLines.end() ) {
        replaceMultipleNewlines( *m );
        ++m;
    }
    codeLocation.start();
}
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
    ui->setupUi(this);

    scene = new InteractiveGraphicsScene();
    ui->graphicsView->setScene(scene);

    connect(ui->splitBtn, SIGNAL(clicked()), this, SLOT(splitLines()));
    connect(ui->exportBtn, SIGNAL(clicked()), this, SLOT(exportLineSegments()));
}
Exemplo n.º 3
0
QStringList Font::tokenizeForWrapping(const QString& str) const {
    QStringList tokens;
    for(auto line : splitLines(str)) {
        if (!tokens.empty()) {
            tokens << QString('\n');
        }
        tokens << line.split(' ');
    }
    return tokens;
}
void GlyphArrangement::addFittedText (const Font& f,
                                      const String& text,
                                      const float x, const float y,
                                      const float width, const float height,
                                      Justification layout,
                                      int maximumLines,
                                      float minimumHorizontalScale)
{
    if (minimumHorizontalScale == 0.0f)
        minimumHorizontalScale = Font::getDefaultMinimumHorizontalScaleFactor();

    // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
    jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);

    if (text.containsAnyOf ("\r\n"))
    {
        addLinesWithLineBreaks (text, f, x, y, width, height, layout);
    }
    else
    {
        const int startIndex = glyphs.size();
        const String trimmed (text.trim());
        addLineOfText (f, trimmed, x, y);
        const int numGlyphs = glyphs.size() - startIndex;

        if (numGlyphs > 0)
        {
            const float lineWidth = glyphs.getReference (glyphs.size() - 1).getRight()
                                      - glyphs.getReference (startIndex).getLeft();

            if (lineWidth > 0)
            {
                if (lineWidth * minimumHorizontalScale < width)
                {
                    if (lineWidth > width)
                        stretchRangeOfGlyphs (startIndex, numGlyphs, width / lineWidth);

                    justifyGlyphs (startIndex, numGlyphs, x, y, width, height, layout);
                }
                else if (maximumLines <= 1)
                {
                    fitLineIntoSpace (startIndex, numGlyphs, x, y, width, height,
                                      f, layout, minimumHorizontalScale);
                }
                else
                {
                    splitLines (trimmed, f, startIndex, x, y, width, height,
                                maximumLines, lineWidth, layout, minimumHorizontalScale);
                }
            }
        }
    }
}
Exemplo n.º 5
0
// Takes raw kif and process it
QStringList Parser::cleanRawKif(const QStringList &rawKif){
    QStringList answer;

    answer = splitLines(rawKif);
    answer = removeComments(answer);
    answer = makePureLines(answer);
    answer = createDoeses(answer);

    debugStringList(answer, "Clean KIF");

    return answer;
}
Exemplo n.º 6
0
   // Function:      displayHomePage
   // Description:   Iterates through current user's posts and tweets as well as his friends posts and tweets and prints
   //                them out in reverse chronological order. If there are more than 3 messages total, will print the first
   //                3 messages and then prompt the user if they wish to see more. If there are 3 or less, will not prompt user
   //                to see more.
   void Menu::displayHomePage()  
   {
      bool hasBeenPrompted = false;
      // Get up to date list of valid users
      initializeValidUsers();
      // Make sure User's friend list is up to date
      currentUser->initializeFriendsVector();
      // Reread in messages so they are up to date
      initializeMessageList();
      // Sort them again
      messageList.sort(chronological_sort);
      // Get the number of valid messages
      int numberOfPostsToDisplay = numberOfUserAndFriendsPosts();
      int numberOfPostsDisplayed = 0;
      list<Message*>::iterator message_iter;

      cout << "\t======================================================\n";
      cout << "\t                   " + currentUser->toString(); 
      cout << "'s Home Page";
      cout << "              \n";
      cout << "\t======================================================\n";
      for( message_iter = messageList.begin(); message_iter != messageList.end(); message_iter++)
      {
         if( numberOfPostsDisplayed == 3 && numberOfPostsToDisplay > 3 && hasBeenPrompted == false) // Three messages have been printed
         { // Prompt user if they wish to see more
            hasBeenPrompted = true;
            if( promptMoreMessages() != true )
            {
               break;
            }
         }
         // Add all of current user and his friends posts, plus all tweets
         if( currentUser->name == (*message_iter)->poster || currentUser->isFriendsWith((*message_iter)->poster)
            || (*message_iter)->type == TWEET)
         {
            //display message either tweet or message of current user or friends
            string output = splitLines((*message_iter)->message);
            cout<< (*message_iter)->poster << " ~ " << output << endl;
            numberOfPostsDisplayed++;
         }
      }
      cout << "\t======================================================\n";
      cout << "\t               End of " + currentUser->toString(); 
      cout << "'s Home Page";
      cout << "              \n";
      cout << "\t======================================================\n";
   }
Exemplo n.º 7
0
void WidgetText::render(const Common::String &str) {
	Common::StringArray lines;
	_remainingText = splitLines(str, lines, _bounds.width() - _surface.widestChar() * 2,
		_bounds.height() / (_surface.fontHeight() + 1));

	// Allocate a surface for the window
	_surface.create(_bounds.width(), _bounds.height());
	_surface.fill(TRANSPARENCY);

	// Form the background for the new window
	makeInfoArea();

	int yp = 5;
	for (int lineNum = 0; yp < (_bounds.height() - _surface.fontHeight() / 2); ++lineNum) {
		_surface.writeString(lines[lineNum], Common::Point(_surface.widestChar(), yp), INFO_TOP);
		yp += _surface.fontHeight() + 1;
	}
}
Exemplo n.º 8
0
void WidgetText::load(const Common::String &str, int speaker) {
	Screen &screen = *_vm->_screen;
	Talk &talk = *_vm->_talk;
	TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui;
	Common::StringArray lines;

	// If bounds for a window have not yet been calculated, figure them out
	if (_surface.empty()) {
		int width = SHERLOCK_SCREEN_WIDTH / 3;
		int height;

		for (;;) {
			splitLines(str, lines, width - _surface.widestChar() * 2, 100);
			height = (screen.fontHeight() + 1) * lines.size() + 9;

			if ((width - _surface.widestChar() * 2 > height * 3 / 2) || (width - _surface.widestChar() * 2
					> SHERLOCK_SCREEN_WIDTH * 3 / 4))
				break;

			width += (width / 4);
		}

		// See if it's only a single line long
		if (height == _surface.fontHeight() + 10) {
			width = _surface.widestChar() * 2 + 6;
			
			const char *strP = str.c_str();
			while (*strP && (*strP < talk._opcodes[OP_SWITCH_SPEAKER] || *strP == talk._opcodes[OP_NULL]))
				width += _surface.charWidth(*strP++);
		}

		_bounds = Common::Rect(width, height);
		
		if (speaker == -1) {
			// No speaker specified, so center window on look position
			_bounds.translate(ui._lookPos.x - width / 2, ui._lookPos.y - height / 2);
		} else {
			// Speaker specified, so center the window above them
			centerWindowOnSpeaker(speaker);
		}
	}

	render(str);
}
Exemplo n.º 9
0
   // Function:      displayWallPage
   // Description:   Iterates through current user's posts and tweets prints them out in reverse chronological order. If there 
   //                are more than 3 messages total, will print the first 3 messages and then prompt the user if they wish to 
   //                see more. If there are 3 or less, will not prompt user to see more.
   void Menu::displayWall()   
   {
      bool hasBeenPrompted = false;
      // Reread all messages
      initializeMessageList();
      // Sort all messages
      messageList.sort(chronological_sort);
      // Get the number of valid messages
      int numberOfPostsToDisplay = numberOfUserPosts();
      int numberOfPostsDisplayed = 0;
      list<Message*>::iterator message_iter;

      cout<<"\t======================================================\n";
      cout<<"\t                   " + currentUser->toString(); 
      cout<<"'s Wall Page";
      cout<<"              \n";
      cout<<"\t======================================================\n";
      
      for( message_iter = messageList.begin(); message_iter != messageList.end(); message_iter++)
      {
         if( numberOfPostsDisplayed == 3 && numberOfPostsToDisplay > 3 && hasBeenPrompted == false) // Three messages have been printed
         { // Prompt user if they wish to see more
            hasBeenPrompted = true;
            if( promptMoreMessages() != true )
            {
               break;
            }
         }
         if( currentUser->name == (*message_iter)->poster )
         {
            //display message
            string output = splitLines((*message_iter)->message);
            cout<<output<<endl;
            numberOfPostsDisplayed++;
         }
      }
      cout<<"\t======================================================\n";
      cout<<"\t               End of " + currentUser->toString(); 
      cout<<"'s Wall Page";
      cout<<"              \n";
      cout<<"\t======================================================\n";
   }
Exemplo n.º 10
0
static void displayLocation(LocationPtr location, int &line, int &column) {
    int tabColumn;
    computeLineCol(location, line, column, tabColumn);
    vector<string> lines;
    splitLines(location->source, lines);
    fprintf(stderr, "###############################\n");
    for (int i = line-2; i <= line+2; ++i) {
        if ((i < 0) || (i >= (int)lines.size()))
            continue;
        fprintf(stderr, "%s", lines[i].c_str());
        if (!endsWithNewline(lines[i]))
            fprintf(stderr, "\n");
        if (i == line) {
            for (int j = 0; j < tabColumn; ++j)
                fprintf(stderr, "-");
            fprintf(stderr, "^\n");
        }
    }
    fprintf(stderr, "###############################\n");
}
Exemplo n.º 11
0
// Indent all lines by 4 spaces
std::string indentLines(std::string inp) {
    std::vector<std::string> lines = splitLines(inp);
	for (unsigned i = 0; i < lines.size(); i++) lines[i] = "    "+lines[i];
    return joinLines(lines);
}
Exemplo n.º 12
0
void
OptionsCont::printHelp(std::ostream &os) throw() {
    std::vector<std::string>::const_iterator i, j;
    // print application description
    os << ' ' << std::endl;
    splitLines(os, myAppDescription , 0, 0);
    os << std::endl;
    // print usage BNF
    os << "Usage: " << myAppName << " [OPTION]*" << std::endl;
    os << ' ' << std::endl;
    // print usage examples
    if (myCallExamples.size()>1) {
        os << " Examples:" << std::endl;
    } else if (myCallExamples.size()!=0) {
        os << " Example:" << std::endl;
    }
    if (myCallExamples.size()!=0) {
        for (i=myCallExamples.begin(); i!=myCallExamples.end(); ++i) {
            os << "  " << myAppName << ' ' << (*i) << std::endl;
        }
    }
    os << ' ' << std::endl;
    // print additional text if any
    if (myAdditionalMessage.length()>0) {
        os << myAdditionalMessage << std::endl << ' ' << std::endl;
    }
    // print the options
    // check their sizes first
    //  we want to know how large the largest not-too-large-entry will be
    size_t tooLarge = 40;
    size_t maxSize = 0;
    for (i=mySubTopics.begin(); i!=mySubTopics.end(); ++i) {
        const std::vector<std::string> &entries = mySubTopicEntries[*i];
        for (j=entries.begin(); j!=entries.end(); ++j) {
            Option *o = getSecure(*j);
            // name, two leading spaces and "--"
            size_t csize = (*j).length() + 2 + 4;
            // abbreviation length ("-X, "->4chars) if any
            std::vector<std::string> synonymes = getSynonymes(*j);
            if (find_if(synonymes.begin(), synonymes.end(), abbreviation_finder())!=synonymes.end()) {
                csize += 4;
            }
            // the type name
            if (!o->isBool()) {
                csize += 1 + o->getTypeName().length();
            }
            // divider
            csize += 2;
            if (csize<tooLarge&&maxSize<csize) {
                maxSize = csize;
            }
        }
    }

    for (i=mySubTopics.begin(); i!=mySubTopics.end(); ++i) {
        os << ' ' << *i << " Options:" << std::endl;
        const std::vector<std::string> &entries = mySubTopicEntries[*i];
        for (j=entries.begin(); j!=entries.end(); ++j) {
            // start length computation
            size_t csize = (*j).length() + 2;
            Option *o = getSecure(*j);
            os << "  ";
            // write abbreviation if given
            std::vector<std::string> synonymes = getSynonymes(*j);
            std::vector<std::string>::iterator a = find_if(synonymes.begin(), synonymes.end(), abbreviation_finder());
            if (a!=synonymes.end()) {
                os << '-' << (*a) << ", ";
                csize += 4;
            }
            // write leading '-'/"--"
            os << "--";
            csize += 2;
            // write the name
            os << *j;
            // write the type if not a bool option
            if (!o->isBool()) {
                os << ' ' << o->getTypeName();
                csize += 1 + o->getTypeName().length();
            }
            csize += 2;
            // write the description formatting it
            os << "  ";
            size_t r;
            for (r=maxSize; r>csize; --r) {
                os << ' ';
            }
            std::string desc = o->getDescription();
            size_t offset = csize > tooLarge ? csize : maxSize;
            splitLines(os, desc, offset, maxSize);
        }
        os << std::endl;
    }
}
Exemplo n.º 13
0
void ofxTextBox::setText(string text) {
    lines = splitLines(text);
}
Exemplo n.º 14
0
std::string FormatBlock(const ParserDefinition *pd, Keywords& keywords, const std::string &format)
{
	std::stringstream ss;
	std::vector<std::string> lines;
	std::vector<std::string> params = keywords["$PARAM"];
	std::string format_copy(format);
	const char *eol = getEolStr();

	// Replace keywords
	stringReplace(format_copy, "$@", pd->command_prefix);
	stringReplace(format_copy, "$FILENAME", keywords["$FILENAME"][0]);
	
	// $FUNCTION may not exist
	if(keywords.find("$FUNCTION") != keywords.end())
		stringReplace(format_copy, "$FUNCTION", keywords["$FUNCTION"][0]);
	else
		stringReplace(format_copy, "$FUNCTION", "");

	lines = splitLines(format_copy, "\r\n");

	for(unsigned int i = 0; i < lines.size(); ++i)
	{
		if(lines[i].find("$PARAM") != std::string::npos)
		{
			// Duplicate the current line for each $PARAM
			std::vector<std::string> formatted_lines;
			for(unsigned int j = 0; j < params.size(); ++j)
			{
				// Make a copy of lines[i] before calling stringReplace
				std::string line = lines[i];
				stringReplace(line, "$PARAM", params[j]);
				formatted_lines.push_back(line);
			}

			// If the align flag is set, align the lines, else remove all "$|" flags
			if(pd->align)
				alignLines(formatted_lines);
			else
				for(unsigned int j = 0; j < formatted_lines.size(); ++j)
					stringReplace(formatted_lines[j], "$|", "");

			// Insert the lines
			for(unsigned int j = 0; j < formatted_lines.size(); ++j)
			{
				if(i == 0 && j == 0)
					ss << pd->doc_start << formatted_lines[j] << eol;
				else if(i == lines.size() - 1 && j == formatted_lines.size() - 1)
					ss << pd->doc_end << formatted_lines[j] << eol;
				else
					ss << pd->doc_line << formatted_lines[j] << eol;
			}
		}
		else
		{
			if(i == 0)
				ss << pd->doc_start << lines[i] << eol;
			else if(i == lines.size() -1)
				ss << pd->doc_end << lines[i];
			else
				ss << pd->doc_line << lines[i] << eol;
		}
	}

	return ss.str();
}
Exemplo n.º 15
0
struct svm_model* svm_load_model_string(char *modelString){

  /* redefinition from svm.cpp */
  char *svm_type_table[]={"c_svc","nu_svc","one_class","epsilon_svr","nu_svr",NULL};
  char *kernel_type_table[]={"linear","polynomial","rbf","sigmoid",NULL};

  struct svm_model *model;
  char **lines, **fields;
  int i,j,k,l,m;
  char *key, *value, *field;
  char c;
  int dataStart, elements;
  int isColon;
  struct svm_node *x_space=NULL;
  
  model = (struct svm_model*)space(sizeof(struct svm_model));

  model->rho = NULL;
  model->probA = NULL;
  model->probB = NULL;
  model->label = NULL;
  model->nSV = NULL;


  /* Read header until support vectors start */
  lines=splitLines(modelString);
  i=0;
  while (strcmp(lines[i],"SV")!=0){
	fields=splitFields(lines[i]);

	key=fields[0];
	  
	if(strcmp(key,"svm_type")==0){
	  value=fields[1];
	  for(j=0;svm_type_table[j];j++){
		if(strcmp(svm_type_table[j],value)==0){
		  model->param.svm_type=j; 
		  break;
		}
	  }
	  if(svm_type_table[i] == NULL){
		fprintf(stderr,"unknown svm type.\n");
		free(model->rho);
		free(model->label);
		free(model->nSV);
		free(model);
		return NULL;
	  }
	} else
	  
	if(strcmp(key,"kernel_type")==0){
	  value=fields[1];
	  for(j=0;kernel_type_table[j];j++){
		if(strcmp(kernel_type_table[j],value)==0){
		  model->param.kernel_type=j; 
		  break;
		}
	  }
	  if(kernel_type_table[i] == NULL){
		fprintf(stderr,"unknown kernel type.\n");
		free(model->rho);
		free(model->label);
		free(model->nSV);
		free(model);
		return NULL;
	  }
	} else
 
	if (strcmp(key,"gamma")==0){
	  value=fields[1];
	  sscanf(value,"%lf",&model->param.gamma);
	}
	  
	if (strcmp(key,"degree")==0){
	  value=fields[1];
	  sscanf(value,"%lf",&model->param.degree);
	} else 

	if (strcmp(key,"coef0")==0){
	  value=fields[1];
	  sscanf(value,"%lf",&model->param.coef0);
	} else 
	if (strcmp(key,"nr_class")==0){
	  value=fields[1];
	  sscanf(value,"%d",&model->nr_class);
	} else 
	if (strcmp(key,"total_sv")==0){
	  value=fields[1];
	  sscanf(value,"%d",&model->l);
	} else

	if (strcmp(key,"rho")==0){
	  int n = model->nr_class * (model->nr_class-1)/2; 
	  model->rho = (double*)space(sizeof(double)*n);
	  for(j=0;j<n;j++){
		sscanf(fields[j+1],"%lf",&model->rho[j]);
	  }
	} else 

	if (strcmp(key,"nr_sv")==0){
	  int n = model->nr_class;
	  model->nSV = (int*)space(sizeof(int)*n);
	  for(j=0;j<n;j++){
		sscanf(fields[j+1],"%d",&model->nSV[j]);
	  }
	} else

	if (strcmp(key,"label")==0){
	  int n = model->nr_class;
	  model->label = (int*)space(sizeof(int)*n);
	  for(j=0;j<n;j++){
		sscanf(fields[j+1],"%d",&model->label[j]);
	  }
	} else 

	if (strcmp(key,"probA")==0){
	  int n = model->nr_class * (model->nr_class-1)/2;
	  model->probA = (double*)space(sizeof(double)*n);
	  for(j=0;j<n;j++){
		sscanf(fields[j+1],"%lf",&model->probA[j]);
	  }
	} else 

	if (strcmp(key,"probB")==0){
	  int n = model->nr_class * (model->nr_class-1)/2;
	  model->probB = (double*)space(sizeof(double)*n);
	  for(j=0;j<n;j++){
		sscanf(fields[j+1],"%lf",&model->probB[j]);
	  }
	}
	i++;
	freeFields(fields);
  }

  dataStart=i+1;
  elements=0;

  /* Count number of nodes (by counting colons) in advance to allocate
	 memory in one block */
  while (lines[i]!=NULL){
	j=0;
	while ((c=lines[i][j])!='\0'){
	  if (c==':'){
		elements++;
	  }
	  j++;
	}
	elements++;
	i++;
  }

  /* allocate memory for SVs and coefficients */
  m = model->nr_class - 1;
  l = model->l;
  model->sv_coef = (double**)space(sizeof(double*)*m);
  for(i=0;i<m;i++){
	model->sv_coef[i] = (double*)space(sizeof(double)*l);
  }
  model->SV = (struct svm_node**)space(sizeof(struct svm_node*)*l);
	
		
  if(l>0){
	x_space = (struct svm_node*)space(sizeof(struct svm_node)*(elements));
  }
	

  /* parse support vector data */
  
  j=0; 
  for(i=0;i<l;i++){
	fields=splitFields(lines[dataStart+i]);
	model->SV[i] = &x_space[j];
	  
	k=0;
	while ((field=fields[k])!=NULL){
	  if (k<m){
		sscanf(fields[k],"%lf",&model->sv_coef[k][i]);
	  } else {
		sscanf(fields[k],"%d:%lf",&(x_space[j].index),&(x_space[j].value));
		j++;
	  }
	  k++;
	}
	x_space[j++].index = -1;
	freeFields(fields);
  }
  
  freeFields(lines);

  model->free_sv = 1;
  
  return(model);
}