<commit_before>/*
 * Copyright 2012 <NAME>
 *
 * This file is part of LESS CSS Compiler.
 *
 * LESS CSS Compiler is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * LESS CSS Compiler is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with LESS CSS Compiler.  If not, see <http://www.gnu.org/licenses/>. 
 *
 * Author: <NAME> <<EMAIL>>
 */

#include "CssWriter.h"

CssWriter::CssWriter() {
  out = NULL;
  column = 0;
  sourcemap = NULL;
}

CssWriter::CssWriter(std::ostream &out): out(&out), column(0) {
  sourcemap = NULL;
}
CssWriter::CssWriter(std::ostream &out, SourceMapWriter &sourcemap):
  out(&out), column(0), sourcemap(&sourcemap) {
}

CssWriter::~CssWriter() {
}

unsigned int CssWriter::getColumn() {
  return column;
}

void CssWriter::writeStr(const char* str, size_t len) {
  out->write(str, len);
  column += len;
}
void CssWriter::writeToken(const Token &token) {
  writeStr(token.c_str(),
           token.size());
}
void CssWriter::writeTokenList(const TokenList &tokens) {
  TokenList::const_iterator i = tokens.begin();
  
  for(; i != tokens.end(); i++) {
    writeToken(*i);
  }
}

void CssWriter::writeSelector(const TokenList &selector) {
  TokenList::const_iterator it;
  bool newselector = true;

  for (it = selector.begin(); it != selector.end(); it++) {

    if (newselector && sourcemap != NULL) {
      sourcemap->writeMapping(column, *it);
      newselector = false;
    }

    writeToken(*it);

    if ((*it) == ",") 
      newselector = true;
  }
}

void CssWriter::writeValue(const TokenList &value) {
  TokenList::const_iterator it = value.begin();
  const Token* t;

  while(it != value.end() && (*it).type == Token::WHITESPACE) {
    it++;
  }
  
  if (sourcemap != NULL)
    sourcemap->writeMapping(column, *it);
  t = &(*it);
  
  for (; it != value.end(); it++) {
    
    if ((*it).source != t->source ||
        (*it).line != t->line) {
      if (sourcemap != NULL)
        sourcemap->writeMapping(column, (*it));
      t = &(*it);
    }

    writeToken(*it);
  }
}

void CssWriter::writeAtRule(const Token &keyword, const TokenList &rule) {
  if (sourcemap != NULL)
    sourcemap->writeMapping(column, keyword);
  
  writeToken(keyword);
  writeStr(" ", 1);

  if (sourcemap != NULL)
    sourcemap->writeMapping(column, rule.front());
  
  writeTokenList(rule);
  
  writeStr(";", 1);
}

void CssWriter::writeRulesetStart(const TokenList &selector) {
  
  writeSelector(selector);

  writeStr("{", 1);
}

void CssWriter::writeRulesetEnd() {
  writeStr("}", 1);
}

void CssWriter::writeDeclaration(const Token &property, const TokenList &value) {
  if (sourcemap != NULL)
    sourcemap->writeMapping(column, property);

  writeToken(property);
  writeStr(":", 1);

  writeValue(value);
}

void CssWriter::writeDeclarationDeliminator() {
  writeStr(";", 1);
}

void CssWriter::writeMediaQueryStart(const TokenList &selector) {
  writeSelector(selector);
  writeStr("{", 1);
}

void CssWriter::writeMediaQueryEnd() {
  writeStr("}", 1);
}

void CssWriter::writeSourceMapUrl(const char* sourcemap_url) {
  *out << std::endl << "/*# sourceMappingURL=" <<
    sourcemap_url << " */" << std::endl;
}
<commit_msg>Don't add a semicolon after an at-rule with a declaration block.<commit_after>/*
 * Copyright 2012 <NAME>
 *
 * This file is part of LESS CSS Compiler.
 *
 * LESS CSS Compiler is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * LESS CSS Compiler is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with LESS CSS Compiler.  If not, see <http://www.gnu.org/licenses/>. 
 *
 * Author: <NAME> <<EMAIL>>
 */

#include "CssWriter.h"

CssWriter::CssWriter() {
  out = NULL;
  column = 0;
  sourcemap = NULL;
}

CssWriter::CssWriter(std::ostream &out): out(&out), column(0) {
  sourcemap = NULL;
}
CssWriter::CssWriter(std::ostream &out, SourceMapWriter &sourcemap):
  out(&out), column(0), sourcemap(&sourcemap) {
}

CssWriter::~CssWriter() {
}

unsigned int CssWriter::getColumn() {
  return column;
}

void CssWriter::writeStr(const char* str, size_t len) {
  out->write(str, len);
  column += len;
}
void CssWriter::writeToken(const Token &token) {
  writeStr(token.c_str(),
           token.size());
}
void CssWriter::writeTokenList(const TokenList &tokens) {
  TokenList::const_iterator i = tokens.begin();
  
  for(; i != tokens.end(); i++) {
    writeToken(*i);
  }
}

void CssWriter::writeSelector(const TokenList &selector) {
  TokenList::const_iterator it;
  bool newselector = true;

  for (it = selector.begin(); it != selector.end(); it++) {

    if (newselector && sourcemap != NULL) {
      sourcemap->writeMapping(column, *it);
      newselector = false;
    }

    writeToken(*it);

    if ((*it) == ",") 
      newselector = true;
  }
}

void CssWriter::writeValue(const TokenList &value) {
  TokenList::const_iterator it = value.begin();
  const Token* t;

  while(it != value.end() && (*it).type == Token::WHITESPACE) {
    it++;
  }
  
  if (sourcemap != NULL)
    sourcemap->writeMapping(column, *it);
  t = &(*it);
  
  for (; it != value.end(); it++) {
    
    if ((*it).source != t->source ||
        (*it).line != t->line) {
      if (sourcemap != NULL)
        sourcemap->writeMapping(column, (*it));
      t = &(*it);
    }

    writeToken(*it);
  }
}

void CssWriter::writeAtRule(const Token &keyword, const TokenList &rule) {
  if (sourcemap != NULL)
    sourcemap->writeMapping(column, keyword);
  
  writeToken(keyword);
  writeStr(" ", 1);

  if (sourcemap != NULL)
    sourcemap->writeMapping(column, rule.front());
  
  writeTokenList(rule);
  if (rule.back() != "}")
    writeStr(";", 1);
}

void CssWriter::writeRulesetStart(const TokenList &selector) {
  
  writeSelector(selector);

  writeStr("{", 1);
}

void CssWriter::writeRulesetEnd() {
  writeStr("}", 1);
}

void CssWriter::writeDeclaration(const Token &property, const TokenList &value) {
  if (sourcemap != NULL)
    sourcemap->writeMapping(column, property);

  writeToken(property);
  writeStr(":", 1);

  writeValue(value);
}

void CssWriter::writeDeclarationDeliminator() {
  writeStr(";", 1);
}

void CssWriter::writeMediaQueryStart(const TokenList &selector) {
  writeSelector(selector);
  writeStr("{", 1);
}

void CssWriter::writeMediaQueryEnd() {
  writeStr("}", 1);
}

void CssWriter::writeSourceMapUrl(const char* sourcemap_url) {
  *out << std::endl << "/*# sourceMappingURL=" <<
    sourcemap_url << " */" << std::endl;
}

{'fraction_non_alphanumeric': 0.15489279824079163, 'fraction_numerical': 0.0043980208905992305, 'mean_word_length': 3.893745796906523, 'pattern_counts': {'":': 2, '<': 33, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '761151', 'n_tokens_mistral': 2428, 'n_tokens_neox': 2377, 'n_words': 640}