Click here to Skip to main content
15,896,606 members
Articles / Web Development / HTML

HTML and CSS C++ class

Rate me:
Please Sign up or sign in to vote.
1.95/5 (6 votes)
27 Jan 2008CPOL 28.7K   407   16  
Makes handling HTML and CSS in the text form in C/C++ easy
// CSS class created by Yarin Licht, 2008.

#include "css.h"

BOOL CSS::newdoc()
{
   open = FALSE;
   dw = 1000;
   psz = new char[dw];
   if(!psz) return FALSE;
   psz[0] = 0;
   return TRUE;
}

void CSS::deldoc()
{
   delete [] psz;
   dw = 0;
   open = FALSE;
   return;
}

BOOL CSS::div(char *arga = 0)
{
   if(arga)
   {
      if(open)
         strcat(psz, "}\r\n");
      if(psz[0] != 0) strcat(psz, "\r\n");
      strcat(psz, arga);
      strcat(psz, " {\r\n");
      open = TRUE;
   }
   else
   {
      if(!open) return FALSE;
      strcat(psz, "}\r\n");
      open = FALSE;
   }
   if(!extmem(1000, dw - 100)) return FALSE;
   return TRUE;
}

BOOL CSS::tag(char *arga, char *argb)
{
   if(!open || !arga || !argb) return FALSE;
   strcat(psz, "\t");
   strcat(psz, arga);
   strcat(psz, ": ");
   strcat(psz, argb);
   strcat(psz, ";\r\n");
   if(!extmem(1000, dw - 100)) return FALSE;
   return TRUE;
}

BOOL CSS::extmem(DWORD arga, DWORD argb = 0)
{
   if(strlen(psz) < argb) return TRUE;
   char *newpsz = new char[dw + arga];
   if(!newpsz) return FALSE;
   dw += arga;
   newpsz[0] = 0;
   strcpy(newpsz, psz);
   delete [] psz;
   psz = newpsz;
   return TRUE;
}

char *CSS::text()
{
   return psz;
}

// End of file.

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions