view anagram/support/agcstack.cpp @ 0:13d2b8934445

Import AnaGram (near-)release tree into Mercurial.
author David A. Holland
date Sat, 22 Dec 2007 17:52:45 -0500
parents
children
line wrap: on
line source

/*
 * AnaGram, A System for Syntax Directed Programming
 * Copyright 1997-2002 Parsifal Software. All Rights Reserved.
 * See the file COPYING for license and usage terms.
 *
 * agcstk.cpp - character stack
 */

#include "agcstack.h"
#include "assert.h"

//#define INCLUDE_LOGGING
#include "log.h"


AgString AgCharStack::popString(unsigned n) {
  LOGSECTION("AgCharStack::popString(unsigned)");
  assert(n <= size());
  LOGV(size());
  LOGV(n);
  AgString result(n);
  char *p = result.pointer();
  while (n--) {
    p[n] = pop();
  }
  return result;
}

AgString AgCharStack::popString() {
  LOGSECTION("AgCharStack::popString");
  unsigned n = size();
  LOGV(size());
  LOGV(n);
  AgString result(n);
  char *p = result.pointer();
  while (n--) {
    p[n] = pop();
  }
  return result;
}

AgCharStack &AgCharStack::push(const char *s) {
  while (*s) {
    push(*s++);
  }
  return *this;
}

AgCharStack &AgCharStack::push(const char *s, unsigned n) {
  for (unsigned i = 0; i < n; i++) {
    push(s[i]);
  }
  return *this;
}


AgCharStack &AgCharStack::operator << (AgString s) {
  int n = s.size();
  char *p = s.pointer();
  while (n--) {
    (*this) << *p++;
  }
  return *this;
}

AgCharStack &AgCharStack::operator << (const char *s) {
  if (s) {
    while (*s) {
      push(*s++);
    }
  }
  return *this;
}