Exemplo n.º 1
0
QString convertToHTML(const QString &inputParam)
{
  // this code goes over the input string once and replaces all bbtags
  // it encounters. This function is called recursively for every replaced
  // string to convert nested tags.
  //
  // This could be implemented simpler by applying a set of regular expressions
  // for each recognized bb-tag one after the other but that would probably be
  // very inefficient (O(n^2)).

  QString input = inputParam.mid(0).replace("\r\n", "<br/>");
  input.replace("\\\"", "\"").replace("\\'", "'");
  QString result;
  int lastBlock = 0;
  int pos = 0;

  // iterate over the input buffer
  while ((pos = input.indexOf('[', lastBlock)) != -1) {
    // append everything between the previous tag-block and the current one
    result.append(input.midRef(lastBlock, pos - lastBlock));

    if ((pos < (input.size() - 1)) && (input.at(pos + 1) == '/')) {
       // skip invalid end tag
      int tagEnd = input.indexOf(']',  pos) + 1;
      pos = tagEnd;
    } else {
      // convert the tag and content if necessary
      int length = -1;
      QString replacement = BBCodeMap::instance().convertTag(input.mid(pos), length);
      if (length != 0) {
        result.append(convertToHTML(replacement));
        // length contains the number of characters in the original tag
        pos += length;
      } else {
        // nothing replaced
        result.append('[');
        ++pos;
      }
    }
    lastBlock = pos;
  }

  // append the remainder (everything after the last tag)
  result.append(input.midRef(lastBlock));
  return result;
}
Exemplo n.º 2
0
void
xmlhtml_complete  (NET_StreamClass *stream)
{
  XMLHTMLInclusion ss =stream->data_object;
  XMLFile xml = ss->xml;
  xml->numOpenStreams--;
  if (xml->numOpenStreams == 0) { 
  /* direct the stream to the html parser */
    NET_StreamClass *newstream;
    URL_Struct *nurls =   NET_CreateURLStruct(copyString(xml->address), NET_DONT_RELOAD);
    StrAllocCopy(nurls->content_type, TEXT_HTML);
    newstream = NET_StreamBuilder(1,  nurls, (MWContext*) xml->mwcontext);
    xml->stream = newstream;
    convertToHTML(xml);
    newstream->complete(newstream);
    NET_FreeURLStruct(nurls); 
  }     
}
Exemplo n.º 3
0
void
xml_complete (NET_StreamClass *stream)
{
  NET_StreamClass *newstream;
  void *obj=stream->data_object;
  URL_Struct *urls = ((XMLFile)obj)->urls;
  freeMem(((XMLFile)obj)->holdOver);
  freeMem(((XMLFile)obj)->line);
  ((XMLFile)obj)->line = ((XMLFile)obj)->holdOver = NULL; 
  ((XMLFile)obj)->numOpenStreams--;
  if (((XMLFile)obj)->numOpenStreams < 1) {
  /* direct the stream to the html parser */
    URL_Struct *nurls =   NET_CreateURLStruct(copyString(urls->address), NET_DONT_RELOAD);
    StrAllocCopy(nurls->content_type, TEXT_HTML);

    newstream = NET_StreamBuilder(1,  nurls, (MWContext*) ((XMLFile)obj)->mwcontext);
    ((XMLFile)obj)->stream = newstream;
    convertToHTML(((XMLFile)obj));
    newstream->complete(newstream);
    NET_FreeURLStruct(nurls); 
  }
}
Exemplo n.º 4
0
void
xmlcss_complete  (NET_StreamClass *stream)
{
  StyleSheet ss =stream->data_object;
  URL_Struct *urls = ss->urls;
  XMLFile xml = ss->xmlFile;
  freeMem(ss->holdOver);
  freeMem(ss->line);
  ss->line = ss->holdOver = NULL; 
  xml->numOpenStreams--;
  if (xml->numOpenStreams == 0) { 
  /* direct the stream to the html parser */
    NET_StreamClass *newstream;
    URL_Struct *nurls =   NET_CreateURLStruct(copyString(xml->address), NET_DONT_RELOAD);
    StrAllocCopy(nurls->content_type, TEXT_HTML);
    newstream = NET_StreamBuilder(1,  nurls, (MWContext*) xml->mwcontext);
    xml->stream = newstream;
    convertToHTML(xml);
    newstream->complete(newstream);
    NET_FreeURLStruct(nurls); 
  }     
}