Skip to content

Commit

Permalink
Merge pull request #19 from pBxr/new_header_file_for_custom_functions
Browse files Browse the repository at this point in the history
Added a new header file ttwCustomFunctions to collect functions that …
  • Loading branch information
pBxr authored Feb 11, 2024
2 parents 66c3029 + e79edd8 commit 994e36a
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 86 deletions.
3 changes: 1 addition & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ authors:
orcid: "https://orcid.org/0000-0001-5430-1456 "
title: "TagTool_WiZArd"
version: 1.3.1
doi: 10.5281/zenodo.5846850
date-released: 2023-12-03
date-released: 2024-02-11
url: "https://github.com/pBxr/TagTool_WiZArd"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ For preparing the `.csv` files see "--help" function.
## New in v1.3.1

- Added a silent mode that can be called with the argument `--silent`. In this case the applications offers no dialogues or any log information, so it can cooperate better with additional features (e. g. the features and `batch` file added by fabfab1)
- Also added was a function to solve a problem in context of a special project under "Custom functions for special projects" at the end of `ttwFunctions.h`.
- For reasons of clearity a new header file `ttwCustomFunctions` collects functions that don´t belong to the core resp. are needed for special purposes, e. g. in context of a single project or for special feautues (e. g. helping to prepare a special citation style)
- Deleted unused feature "Remove dispensable formattings/tags"
- Deleted confirmation dialogue "Please check before running the application: ..."
- Suppressed function and dialogue for a next run (until ttw is prepared better for re-editing the same content multiple times, see above).
Expand Down
6 changes: 3 additions & 3 deletions TagTool_WiZArd.dev
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ObjectOutput=
LogOutput=
LogOutputEnabled=0
OverrideOutput=1
OverrideOutputName=tagtool_v1-3-2.exe
OverrideOutputName=tagtool_v1-3-1.exe
HostApplication=
UseCustomMakefile=0
CustomMakefile=
Expand All @@ -29,7 +29,7 @@ IncludeVersionInfo=0
SupportXPThemes=0
CompilerSet=0
CompilerSettings=0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;8;0;0;0
UnitCount=5
UnitCount=6

[VersionInfo]
Major=1
Expand Down Expand Up @@ -101,7 +101,7 @@ OverrideBuildCmd=0
BuildCmd=

[Unit6]
FileName=x_ttwUnusedFunctuions.h
FileName=ttwCustomFunctions.h
CompileCpp=1
Folder=
Compile=1
Expand Down
11 changes: 11 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ttwFunctions.h"
#include "ttwFileFunctions.h"
#include "ttwCustomFunctions.h"
#include "ttwClasses.h"
#include "ttwDeclarations.h"

Expand Down Expand Up @@ -80,6 +81,16 @@ vector<string> articleFile{};

analyze_articleFile(articleFile, containerTags, containerLines, documentSections, footnoteAdressContainer);

//Custom function: Apply functions on DAI citation style?____________________________________________________
if(applyCitationStyleSelected==true){

apply_citation_style_hyphens(articleFile, documentSections);

//After alterating the file analyze again
analyze_articleFile(articleFile, containerTags, containerLines, documentSections, footnoteAdressContainer);
console_print("DAI citation style features applied successfully...");
applyCitationStyleDone=true;
}

//Set author year tags?__________________________________________________________________
if (authorYearTagsSelected==true && authorYearTagsSet==false){
Expand Down
2 changes: 2 additions & 0 deletions ttwClasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ bool htmlSelected=true; //=default setting;
bool callFromWebSelected=false;
bool silentModeSelected=false;

bool applyCitationStyleDone=false;
bool authorYearTagsSet=false;
bool footnoteTagsSet=false;
bool htmlHeadReplaced=false;
Expand All @@ -633,6 +634,7 @@ bool customBodyTagsSelected;
bool figureReferenceTagsSelected;
bool insertCreditListSelected;

bool applyCitationStyleSelected;
bool authorYearTagsSelected;
bool paragraphNumbersSelected;
bool toSearchAndReplaceSelected;
Expand Down
142 changes: 142 additions & 0 deletions ttwCustomFunctions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#pragma once
#ifndef TTWCUSTOMFUNCTIONS_H
#define TTWCUSTOMFUNCTIONS_H

#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <vector>
#include <regex>

#include "ttwClasses.h"
#include "ttwDeclarations.h"
#include "ttwFunctions.h"


/*
For reasons of clearity this file collects functions
that don´t belong to the core resp. are needed for special purposes,
e. g. in context of a single project or for special feautues
*/

void apply_citation_style_hyphens(vector<string> &articleFile, struct documentSectionsClass &documentSections){

string citationSearch, citationReplace;
string toReplace;

//find citations like 1993, 3-46 oder 2006b, 300-201... (only in the footnote section)

for(size_t i=documentSections.lineNrFootnotesBegin_; i<articleFile.size(); i++){
std::regex r1{"[0-9]{4}[a-z]?,\\s[0-9]{1,4}[–|\-]{1,3}[0-9]{1,4}"};
std::smatch m1;
std::sregex_iterator begin{ articleFile[i].begin(), articleFile[i].end(), r1};
std::sregex_iterator end;

for (std::sregex_iterator it = begin; it != end; ++it) {
m1=*it;
citationSearch=m1.str();

//now prepare a replace string with the correct hyphen
//and set a green marking to highlight the alteration for the editing process
std::regex r2{"[^.\\w^(^)\\s]{2,4}"};
std::stringstream result;

if(htmlSelected==true){
toReplace = "<span style=\"background-color:green;\">–</span>";
}
else{
toReplace = "";
}

result << std::regex_replace(citationSearch, r2, toReplace);

citationReplace = result.str();

search_replace(articleFile[i], citationSearch, citationReplace);

citationSearch.clear();
citationReplace.clear();
}
}
}


void xml_preparation_tagebuecher (vector<string> &articleFile, struct documentSectionsClass& documentSections){

int pos1;
int pos2;
string toInsert;
string pageNumberStr;


//First detect page numbers to insert figure reference tags
for(int i=0; i<documentSections.lineNrBodyEnd_; i++){

pos1=articleFile[i].find("[S.]");

if(pos1==3){ //3 to be sure to get only the usual page numbers at the beginning ("<p>")
std::regex pattern{"[0-9]{1,3}"};
std::sregex_iterator begin{ articleFile[i].cbegin(), articleFile[i].cend(), pattern};
std::sregex_iterator end;

for (std::sregex_iterator i = begin; i != end; ++i) {
std::smatch match = *i;
pageNumberStr = match.str();
}

pos2=articleFile[i].find("</p>");

if(pos2>=0){

articleFile[i].insert(pos2, figureReferencesClass::figReferenceTagEndXML_);

}

std::regex r1("#");
toInsert = std::regex_replace(figureReferencesClass::figReferenceTagBeginXML_, r1, pageNumberStr);
articleFile[i].insert(pos1, toInsert);
}
}

//Now detect notes at the end of the pages and put them into boxed text

bool boxedTextTagOpen;
int lineNrLastOpenTag;

for(int i=0; i<documentSections.lineNrBodyEnd_; i++){

pos1=articleFile[i].find("[Notizen außerhalb der Textkolumne]");

if(pos1>=0){
//cout << "Treffer: " << articleFile[i] << endl;
articleFile[i].insert(0, "<boxed-text>\n");
boxedTextTagOpen=true;
lineNrLastOpenTag=i;
}

for(int y=i; y<documentSections.lineNrBodyEnd_; y++){
pos2=articleFile[i].find("<p><xref ref-type=\"fig\"");
if(pos2>=0 && boxedTextTagOpen==true){
articleFile[i].insert(0, "</boxed-text>\n");
boxedTextTagOpen=false;
y=documentSections.lineNrBodyEnd_;
}
}
}

if(boxedTextTagOpen==true){
for(int i=lineNrLastOpenTag; i<documentSections.lineNrBodyEnd_; i++){

pos2=articleFile[i].find("</sec>");

if(pos2>=0 && boxedTextTagOpen==true){
articleFile[i].insert(0, "</boxed-text>\n");
boxedTextTagOpen=false;
break;
}
}
}
}

#endif // TTWCUSTOMFUNCTIONS_H
4 changes: 4 additions & 0 deletions ttwDeclarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ using std::endl; using std::stringstream;

void analyze_articleFile(vector<string>&, vector<tagClass>&, vector<lineClass>&,
struct documentSectionsClass&, vector<footNoteClass>&);

void apply_citation_style_hyphens(vector<string>&, struct documentSectionsClass&);

string classify_tag(string, size_t, struct documentSectionsClass&);

Expand Down Expand Up @@ -63,6 +65,8 @@ string resolve_hyphens_in_figRef(string bracketContent);

void saveFile(vector<string>&, fileInformations&);

void search_replace(string &textLine, string termSearch, string termReplace);

void search_replace(vector<string> &articleFile, string termSearch, string termReplace);

void search_replace(vector<string> &textVector, vector<reducedValueClass> valueList);
Expand Down
2 changes: 1 addition & 1 deletion ttwFileFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void get_current_path(fileInformations &fileInfos){
}

vector<string> loadFileContent(string fileName){

vector<string> workingFile_;
string inputLine;

Expand Down
Loading

0 comments on commit 994e36a

Please sign in to comment.