OpenASIP  2.0
Static Public Member Functions | List of all members
StringTools Class Reference

#include <StringTools.hh>

Collaboration diagram for StringTools:
Collaboration graph

Static Public Member Functions

static std::string trim (const std::string &source)
 
static char * stringToCharPtr (const std::string &source)
 
static bool containsChar (const std::string &source, char ch, bool caseSensitive=true)
 
static bool endsWith (const std::string &source, const std::string &searchString)
 
static std::string stringToUpper (const std::string &source)
 
static std::string stringToLower (const std::string &source)
 
static bool ciEqual (const std::string &a, const std::string &b)
 
static std::vector< TCEStringchopString (const std::string &source, const std::string &delimiters)
 
static void chopString (const std::string &source, const std::string &delimiter, std::vector< std::string > &results)
 
static std::string splitToRows (const std::string &original, const unsigned int rowLength)
 
static std::string replaceAllOccurrences (const std::string &source, const std::string &occurrence, const std::string &newString)
 
static std::string indent (int level)
 

Detailed Description

Definition at line 44 of file StringTools.hh.

Member Function Documentation

◆ chopString() [1/2]

void StringTools::chopString ( const std::string &  source,
const std::string &  delimiter,
std::vector< std::string > &  results 
)
static

Chops string using a given delimiter.

Result is returned as a vector. Extra blanks are ignored.

Parameters
sourceString to be chopped.
delimiterDelimiter used.
storeString vector reference where result strings are stored.

Definition at line 212 of file StringTools.cc.

215  {
216 
217  string line = trim(source);
218  while (line.length() > 0) {
219  string::size_type location = line.find(delimiter);
220  if (location == string::npos) {
221  results.push_back(line);
222  line = "";
223  } else {
224  results.push_back(line.substr(0, location));
225  line.replace(0, location + 1, "");
226  line = trim(line);
227  }
228  }
229 }

References trim().

Here is the call graph for this function:

◆ chopString() [2/2]

vector< TCEString > StringTools::chopString ( const std::string &  source,
const std::string &  delimiter 
)
static

Chops string using a given delimiter.

Result is returned as a vector. Extra blanks are ignored.

Parameters
sourceString to be chopped.
delimiterDelimiter used.
Returns
A vector that contains chopped strings.

Definition at line 181 of file StringTools.cc.

183  {
184 
185  string line = trim(source);
186  vector<TCEString> results;
187  while (line.length() > 0) {
188  string::size_type location = line.find(delimiter);
189  if (location == string::npos) {
190  results.push_back(line);
191  line = "";
192  } else {
193  results.push_back(line.substr(0, location));
194  line.replace(0, location + 1, "");
195  line = trim(line);
196  }
197  }
198  return results;
199 }

References trim().

Referenced by UserManualCmd::Do(), VectorLSGenerator::explore(), llvm::LLVMTCERISCVIntrinsicsLowering::findOperationName(), llvm::LLVMTCERISCVIntrinsicsLowering::findRegs(), GenerateProcessor::generateProcessor(), SimpleScriptInterpreter::interpret(), ConfigurationFile::parse(), Environment::parsePathEnvVariable(), and TCEString::split().

Here is the call graph for this function:

◆ ciEqual()

bool StringTools::ciEqual ( const std::string &  a,
const std::string &  b 
)
static

Returns true if two strings are equal if the case is not taken into account.

Parameters
aA string.
bAnother string.
Returns
True if strings equal case-insensitively.

Definition at line 240 of file StringTools.cc.

240  {
241  return (stringToLower(a) == stringToLower(b));
242 }

References stringToLower().

Referenced by MemDumpCommand::execute(), MemWriteCommand::execute(), InfoRegistersCommand::execute(), SimulatorFrontend::findPort(), findRegisterFile(), SocketCodeTable::fuPortCode(), DCMFUResourceConflictDetector::operationID(), ReservationTableFUResourceConflictDetector::operationID(), and SimulatorFrontend::state().

Here is the call graph for this function:

◆ containsChar()

bool StringTools::containsChar ( const std::string &  source,
char  ch,
bool  caseSensitive = true 
)
static

Checks whether a string contains a char or not.

Parameters
sourceThe investigated string.
chCharacter which is checked whether it is in a string or not.
caseSensitiveFlag indicating whether checking is case sensitive or not.
Returns
True, if source string contains ch, false otherwise.

Definition at line 101 of file StringTools.cc.

104  {
105 
106  string::size_type pos = 0;
107  if (!caseSensitive) {
108  char upC = toupper(ch);
109  string upString = StringTools::stringToUpper(source);
110  pos = upString.find(upC, 0);
111  } else {
112  pos = source.find(ch, 0);
113  }
114 
115  return pos != string::npos;
116 }

References stringToUpper().

Referenced by BaseLineReader::charQuestion(), llvm::LLVMTCEBuilder::emitOperationMacro(), llvm::LLVMTCERISCVIntrinsicsLowering::findOperationName(), and llvm::LLVMTCERISCVIntrinsicsLowering::findRegs().

Here is the call graph for this function:

◆ endsWith()

bool StringTools::endsWith ( const std::string &  source,
const std::string &  searchString 
)
static

Checks whether a string ends with the given search string.

Parameters
sourceThe investigated string.
searchStringThe string to search from the end.
Returns
True, if source ends with searchString.

Definition at line 126 of file StringTools.cc.

128  {
129 
130  return source.size() >= searchString.size() &&
131  source.substr(
132  source.size() - searchString.size(), searchString.size()) ==
133  searchString;
134 }

Referenced by AutoSelectImplementationsDialog::AutoSelectImplementationsDialog(), BlockImplementationDialog::BlockImplementationDialog(), PluginTools::findModule(), OperationPropertyDialog::saveOperation(), GenerateProcessor::validIntegratorParameters(), and QuartusProjectGenerator::writeQSFFile().

◆ indent()

std::string StringTools::indent ( int  level)
static

◆ replaceAllOccurrences()

std::string StringTools::replaceAllOccurrences ( const std::string &  source,
const std::string &  occurrence,
const std::string &  newString 
)
static

Replaces all occurrences of 'occurrence' in 'source' with 'newString'

Parameters
sourceThe source string to be modified
occurrenceThe string occurrences to be replaced
newStringThe string that's replaced over the found occurrences
Returns
A string containing the modifications

Definition at line 295 of file StringTools.cc.

298  {
299 
300  std::string modifiedString(source);
301  std::string::size_type location = modifiedString.find(occurrence);
302  while (location != std::string::npos) {
303  modifiedString.replace(modifiedString.begin() + location,
304  modifiedString.begin() + location + occurrence.length(),
305  newString.c_str());
306  location = modifiedString.find(occurrence);
307  }
308 
309  return modifiedString;
310 }

Referenced by llvm::LLVMTCERISCVIntrinsicsLowering::findOperationName(), and ProGeTestBenchGenerator::generate().

◆ splitToRows()

std::string StringTools::splitToRows ( const std::string &  original,
const unsigned int  rowLength 
)
static

Splits a string into rows.

The original string is split in to rows containing a maximum of 'rowLength' characters. After 'rowLength' characters a new-line character is inserted to the string to be returned. If the given string has less than 'rowLength' characters, the string is returned as it was. Also, the "last row" may have less than 'rowLength' characters.

If 'rowLength' is 0, the original string is returned.

Parameters
originalThe string to be split into rows.
rowLengthThe length of a row in the returned string.
Returns
A string that has been split into rows containing a maximum of 'rowLength' characters.

Definition at line 262 of file StringTools.cc.

264  {
265 
266  if (rowLength == 0) {
267  return original;
268  } else {
269 
270  unsigned int counter = 0;
271  string newString = "";
272 
273  while (counter < original.size()) {
274  newString += original.substr(counter, 1);
275  counter++;
276 
277  if (counter % rowLength == 0 && counter != original.size()) {
278  newString += "\n";
279  }
280  }
281 
282  return newString;
283  }
284 }

◆ stringToCharPtr()

char * StringTools::stringToCharPtr ( const std::string &  source)
static

Converts string to char*.

Parameters
sourceThe string to be converted.
Returns
The string as a char*.

Definition at line 83 of file StringTools.cc.

83  {
84  char* ch = new char[source.size() + 1];
85  copy(source.begin(), source.end(), ch);
86  ch[source.size()] = 0;
87  return ch;
88 }

Referenced by TclInterpreter::addCustomCommandToInterpreter(), EditLineReader::charQuestion(), TclInterpreter::dataObjectToTclObj(), EditLineReader::initialize(), TclInterpreter::interpret(), EditLineReader::readLine(), TclInterpreter::removeCustomCommandFromInterpreter(), TclInterpreter::setVariableToInterpreter(), and TclInterpreter::variable().

◆ stringToLower()

string StringTools::stringToLower ( const std::string &  source)
static

Converts a string to lower case letters.

Parameters
sourceString to be converted.
Returns
String as lower case letters.

Definition at line 160 of file StringTools.cc.

160  {
161 
162  string lowString;
163  lowString.reserve(source.length());
164  for (unsigned int i = 0; i < source.length(); ++i) {
165  lowString.push_back(tolower(source[i]));
166  }
167  return lowString;
168 }

Referenced by MachineState::addPortState(), StaticProgramAnalyzer::addProgram(), MachineStateBuilder::addVirtualOpcodeSettingPortsToFU(), InputFUBroker::allAvailableResources(), ConfigurationFile::booleanValue(), DesignSpaceExplorerPlugin::booleanValue(), DataObject::boolValue(), FUGen::buildReplaces(), MachineConnectivityCheck::busConnectedToAnyFU(), ProGeTools::canGenerateFromDAG(), Automagic::canGenerateFromDAG(), TCEString::capitalize(), ciEqual(), FUGen::constantName(), FUGen::createOperationResources(), FUGen::DAGNodeOperandWidth(), ProGe::CUOpcodeGenerator::encodings(), StrictMatchFUEstimator::estimateEnergy(), InterpolatingFUEstimator::estimateEnergy(), EnableBPCommand::execute(), InfoCommand::execute(), SettingCommand::execute(), InfoProcCommand::execute(), InfoStatsCommand::execute(), InfoProgramCommand::execute(), ProGeTools::findInOptionList(), Automagic::findInOptionList(), llvm::LLVMTCERISCVIntrinsicsLowering::findOperationName(), SimulatorFrontend::findPort(), ComponentImplementationSelector::fuArchsByOpSetWithMinLatency(), FUGen::FUGen(), ProGeTools::generateableDAGOperations(), Automagic::generateableDAGOperations(), llvm::LLVMTCEBuilder::getHWOperation(), MachineInfo::getOpset(), TTAMachine::FunctionUnit::hasOperation(), TTAMachine::HWOperation::HWOperation(), llvm::LLVMTCEBuilder::initDataSections(), POMDisassembler::isCallOrJump(), FUTestbenchGenerator::isShiftOrRotOp(), TDGen::llvmOperationName(), TDGen::llvmOperationPattern(), llvm::LLVMTCEIRBuilder::LLVMTCEIRBuilder(), TCEString::lower(), MachineInfo::maxMemoryAlignment(), Automagic::nodeLatency(), ProGeTools::nodeLatency(), OperationPoolPimpl::operation(), TTAMachine::FunctionUnit::operation(), FUResourceConflictDetector::operationID(), TTAMachine::OperationTriggeredOperand::OperationTriggeredOperand(), SimControlLanguageCommand::parseBreakpoint(), MachineState::portState(), FUGen::prepareSnippet(), SimProgramBuilder::processBidirTerminal(), FUGen::readFile(), FUGen::readImplementation(), FUGen::scheduleOperations(), TTAMachine::OperationTriggeredOperand::setName(), TTAMachine::HWOperation::setName(), FUGen::subOpConnection(), FUGen::subOpName(), TDGen::writeBackendCode(), and FUTestbenchGenerator::writeInputPortStimulus().

◆ stringToUpper()

string StringTools::stringToUpper ( const std::string &  source)
static

Converts a string to upper case letters.

Parameters
sourceString to be converted.
Returns
String as upper case letters.

Definition at line 143 of file StringTools.cc.

143  {
144  string upString;
145  upString.reserve(source.length());
146  for (unsigned int i = 0; i < source.length(); ++i) {
147  upString.push_back(toupper(source[i]));
148  }
149  return upString;
150 }

Referenced by UtilizationStats::calculateForInstruction(), TCEString::capitalize(), ConfigurationFile::checkSemantics(), containsChar(), ProximFUDetailsCmd::Do(), TDGen::emulatingOpNodeLLVMName(), InfoProcCommand::execute(), InfoStatsCommand::execute(), ExecutionPipelineResourceTable::ExecutionPipelineResourceTable(), SimulatorFrontend::finishSimulation(), FUFiniteStateAutomaton::FUFiniteStateAutomaton(), generateHeader(), TDGen::getLLVMPatternWithConstants(), HDB::FUImplementation::hasOpcode(), OperationBehaviorLoader::importBehavior(), OperationPimpl::loadState(), HDB::FUImplementation::opcode(), FUFiniteStateAutomaton::operationCollisionMatrix(), ResourceVectorFUResourceConflictDetector::operationID(), FSAFUResourceConflictDetector::operationID(), TTAMachine::ResourceVectorSet::resourceVector(), TTAMachine::ResourceVectorSet::ResourceVectorSet(), DataDependenceGraph::setMachine(), HDB::FUImplementation::setOpcode(), TDGen::supportedStackAccessOperations(), OperationSerializer::toOperation(), HDB::FUImplementation::unsetOpcode(), OperationPropertyDialog::updateOperation(), TCEString::upper(), TDGen::writeInstrInfo(), TDGen::writeOperationDef(), ProGe::CUOpcodeGenerator::WriteVerilogOpcodePackage(), and ProGe::CUOpcodeGenerator::WriteVhdlOpcodePackage().

◆ trim()

std::string StringTools::trim ( const std::string &  source)
static

Removes leading and trailing whitespace from the string.

Returns
The trimmed string.
Parameters
sourceThe string to trim.

Definition at line 55 of file StringTools.cc.

55  {
56 
57  string result = "";
58  int i = 0;
59 
60  // remove leading white space
61  while (i < static_cast<int>(source.size()) && isspace(source[i])) {
62  ++i;
63  }
64  result = source.substr(i);
65 
66  i = result.size() - 1;
67  while (i >= 0 && isspace(result[i])) {
68  --i;
69  }
70  result = result.substr(0, i+1);
71 
72  return result;
73 }

Referenced by SimControlLanguageCommand::askConditionFromUser(), SimControlLanguageCommand::askExpressionFromUser(), PlatformIntegrator::chopSignalToTag(), chopString(), IPXactHibiInterface::createInstanceName(), ProximSimulationThread::Entry(), CommandsCommand::execute(), EnableBPCommand::execute(), ProjectFileGenerator::extractFUName(), HDLTemplateInstantiator::getPlaceholderDefault(), HDLTemplateInstantiator::getPlaceholderKey(), SimpleScriptInterpreter::interpret(), TclInterpreter::interpret(), main(), ConfigurationFile::parse(), SimControlLanguageCommand::parseDataAddressExpression(), SimControlLanguageCommand::parseInstructionAddressExpression(), SimulatorCLI::run(), OperationPropertyDialog::saveOperation(), DesignSpaceExplorer::simulate(), ConfigurationFile::timeStampValue(), and EditLineReader::updateHistory().


The documentation for this class was generated from the following files:
StringTools::indent
static std::string indent(int level)
Definition: StringTools.cc:319
StringTools::stringToUpper
static std::string stringToUpper(const std::string &source)
Definition: StringTools.cc:143
StringTools::trim
static std::string trim(const std::string &source)
Definition: StringTools.cc:55
StringTools::stringToLower
static std::string stringToLower(const std::string &source)
Definition: StringTools.cc:160