Skip to content

Commit

Permalink
Add comment functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
craigsapp committed Jan 18, 2021
1 parent c811c2d commit e494381
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 88 deletions.
2 changes: 2 additions & 0 deletions include/HumdrumToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ class HumdrumToken : public std::string, public HumHash {

bool isBarline (void) const;
bool isCommentLocal (void) const;
bool isLocalComment (void) const { return isCommentLocal(); }
bool isCommentGlobal (void) const;
bool isGlobalComment (void) const { return isCommentGlobal(); }
bool isComment (void) const;
bool isData (void) const;
bool isInterpretation (void) const;
Expand Down
7 changes: 5 additions & 2 deletions include/humlib.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Sat Aug 8 12:24:49 PDT 2015
// Last Modified: Thu Dec 17 23:34:26 PST 2020
// Last Modified: Sun Jan 17 19:09:22 PST 2021
// Filename: humlib.h
// URL: https://github.com/craigsapp/humlib/blob/master/include/humlib.h
// Syntax: C++11
Expand All @@ -10,7 +10,8 @@
// Description: Include file for humlib library.
//
/*
Copyright (c) 2015-2020 Craig Stuart Sapp
https://github.com/craigsapp/humlib
Copyright (c) 2015-2021 Craig Stuart Sapp
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -1466,7 +1467,9 @@ class HumdrumToken : public std::string, public HumHash {

bool isBarline (void) const;
bool isCommentLocal (void) const;
bool isLocalComment (void) const { return isCommentLocal(); }
bool isCommentGlobal (void) const;
bool isGlobalComment (void) const { return isCommentGlobal(); }
bool isComment (void) const;
bool isData (void) const;
bool isInterpretation (void) const;
Expand Down
134 changes: 92 additions & 42 deletions src/HumdrumLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,11 @@ string HumdrumLine::getReferenceValue(void) const {

//////////////////////////////
//
// HumdrumLine::getUniversalReferenceKey -- Return reference key if a
// HumdrumLine::getUniversalReferenceValue -- Return reference value if a
// universal reference record. Otherwise returns an empty string.
//

string HumdrumLine::getUniversalReferenceKey(void) const {
string HumdrumLine::getUniversalReferenceValue(void) const {
if (this->size() < 6) {
return "";
}
Expand All @@ -528,30 +528,42 @@ string HumdrumLine::getUniversalReferenceKey(void) const {
if ((*this)[4] == '!') {
return "";
}
int spaceloc = (int)this->find(" ");
int tabloc = (int)this->find("\t");
int colloc = (int)this->find(":");
if (colloc == (int)string::npos) {

size_t colloc = this->find(":");
if (colloc == string::npos) {
return "";
}
if ((spaceloc != (int)string::npos) && (spaceloc < colloc)) {
return "";
int index = (int)colloc + 1;
for (int i=index; i<(int)this->size(); i++) {
if (isspace(this->at(i))) {
index++;
continue;
}
break;
}
if ((tabloc != (int)string::npos) && (tabloc < colloc)) {
if (index >= (int)this->size()) {
return "";
}
return this->substr(4, colloc - 4);
string output = this->substr(index);
for (int i=(int)output.size() - 1; i>=0; i--) {
if (isspace(output.at(i))) {
output.resize((int)output.size() - 1);
continue;
}
break;
}
return output;
}



//////////////////////////////
//
// HumdrumLine::getGlobalReferenceKey -- Return reference key if a
// universal reference record. Otherwise returns an empty string.
// HumdrumLine::getGlobalReferenceValue -- Return reference value if a
// global reference record. Otherwise returns an empty string.
//

string HumdrumLine::getGlobalReferenceKey(void) const {
string HumdrumLine::getGlobalReferenceValue(void) const {
if (this->size() < 6) {
return "";
}
Expand All @@ -561,30 +573,43 @@ string HumdrumLine::getGlobalReferenceKey(void) const {
if ((*this)[4] == '!') {
return "";
}
int spaceloc = (int)this->find(" ");
int tabloc = (int)this->find("\t");
int colloc = (int)this->find(":");
if (colloc == (int)string::npos) {

size_t colloc = this->find(":");
if (colloc == string::npos) {
return "";
}
if ((spaceloc != (int)string::npos) && (spaceloc < colloc)) {
return "";
int index = (int)colloc + 1;
for (int i=index; i<(int)this->size(); i++) {
if (isspace(this->at(i))) {
index++;
continue;
}
break;
}
if ((tabloc != (int)string::npos) && (tabloc < colloc)) {
if (index >= (int)this->size()) {
return "";
}
return this->substr(3, colloc - 3);
string output = this->substr(index);
for (int i=(int)output.size() - 1; i>=0; i--) {
if (isspace(output.at(i))) {
output.resize((int)output.size() - 1);
continue;
}
break;
}
return output;
}



//////////////////////////////
//
// HumdrumLine::getGlobalReferenceValue -- Return reference value if a reference
// HumdrumLine::getGlobalReferenceKey -- Return reference key if a reference
// record. Otherwise returns an empty string.
//

string HumdrumLine::getGlobalReferenceValue(void) const {
string HumdrumLine::getGlobalReferenceKey(void) const {

if (this->size() < 5) {
return "";
}
Expand All @@ -594,30 +619,42 @@ string HumdrumLine::getGlobalReferenceValue(void) const {
if ((*this)[3] == '!') {
return "";
}
int spaceloc = (int)this->find(" ");
int tabloc = (int)this->find("\t");
int colloc = (int)this->find(":");
if (colloc == (int)string::npos) {
size_t colloc = this->find(":");
if (colloc == string::npos) {
return "";
}
if ((spaceloc != (int)string::npos) && (spaceloc < colloc)) {
return "";
int index = 3;
for (int i=index; i<(int)colloc; i++) {
if (isspace(this->at(i))) {
index++;
continue;
}
break;
}
if ((tabloc != (int)string::npos) && (tabloc < colloc)) {
if (index >= (int)colloc) {
return "";
}
return Convert::trimWhiteSpace(this->substr(colloc+1));
int length = colloc - index;
string output = this->substr(index, length);
for (int i=(int)output.size()-1; i>=0; i--) {
if (isspace(output.at(i))) {
output.resize((int)output.size() - 1);
}
}
return output;

}



//////////////////////////////
//
// HumdrumLine::getUniversalReferenceValue -- Return reference value if a reference
// HumdrumLine::getUniversalReferenceKey -- Return reference key if a reference
// record. Otherwise returns an empty string.
//

string HumdrumLine::getUniversalReferenceValue(void) const {
string HumdrumLine::getUniversalReferenceKey(void) const {

if (this->size() < 6) {
return "";
}
Expand All @@ -627,19 +664,30 @@ string HumdrumLine::getUniversalReferenceValue(void) const {
if ((*this)[4] == '!') {
return "";
}
int spaceloc = (int)this->find(" ");
int tabloc = (int)this->find("\t");
int colloc = (int)this->find(":");
if (colloc == (int)string::npos) {
size_t colloc = this->find(":");
if (colloc == string::npos) {
return "";
}
if ((spaceloc != (int)string::npos) && (spaceloc < colloc)) {
return "";
int index = 4;
for (int i=index; i<(int)colloc; i++) {
if (isspace(this->at(i))) {
index++;
continue;
}
break;
}
if ((tabloc != (int)string::npos) && (tabloc < colloc)) {
if (index >= (int)colloc) {
return "";
}
return Convert::trimWhiteSpace(this->substr(colloc+1));
int length = colloc - index;
string output = this->substr(index, length);
for (int i=(int)output.size()-1; i>=0; i--) {
if (isspace(output.at(i))) {
output.resize((int)output.size() - 1);
}
}
return output;

}


Expand Down Expand Up @@ -1746,8 +1794,10 @@ ostream& HumdrumLine::printXml(ostream& out, int level, const string& indent) {
out << "/>\n";

out << Convert::repeatString(indent, level) << "<frameType>";
if (isReference()) {
if (isGlobalReference()) {
out << "reference";
} else if (isUniversalReference()) {
out << "ureference";
} else if (isBlank()) {
out << "empty";
} else {
Expand Down
Loading

0 comments on commit e494381

Please sign in to comment.