Skip to content

Commit

Permalink
use front() and back()
Browse files Browse the repository at this point in the history
Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Jan 28, 2025
1 parent 112112e commit d7ac558
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1864,7 +1864,7 @@ int renameFile(std::string& newPath, const tm* tm) {
std::cout << Params::instance().progname() << ": " << _("File") << " `" << newPath << "' "
<< _("exists. [O]verwrite, [r]ename or [s]kip?") << " ";
std::cin >> s;
switch (s.at(0)) {
switch (s.front()) {
case 'o':
case 'O':
go = false;
Expand Down Expand Up @@ -1915,7 +1915,7 @@ int dontOverwrite(const std::string& path) {
std::cout << Params::instance().progname() << ": " << _("Overwrite") << " `" << path << "'? ";
std::string s;
std::cin >> s;
if (s.at(0) != 'y' && s.at(0) != 'Y')
if (s.front() != 'y' && s.front() != 'Y')
return 1;
}
return 0;
Expand Down
8 changes: 4 additions & 4 deletions samples/iptctest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main(int argc, char* const argv[]) {
}

bool processLine(const std::string& line, int num, IptcData& iptcData) {
switch (line.at(0)) {
switch (line.front()) {
case 'a':
case 'A':
processAdd(line, num, iptcData);
Expand All @@ -64,7 +64,7 @@ bool processLine(const std::string& line, int num, IptcData& iptcData) {
return false;
default:
std::ostringstream os;
os << "Unknown command (" << line.at(0) << ") at line " << num;
os << "Unknown command (" << line.front() << ") at line " << num;
throw Error(ErrorCode::kerErrorMessage, os.str());
}
return true;
Expand All @@ -86,7 +86,7 @@ void processAdd(const std::string& line, int num, IptcData& iptcData) {

std::string data(line.substr(dataStart));
// if data starts and ends with quotes, remove them
if (data.at(0) == '\"' && data.at(data.size() - 1) == '\"') {
if (data.front() == '\"' && data.back() == '\"') {
data = data.substr(1, data.size() - 2);
}
TypeId type = IptcDataSets::dataSetType(iptcKey.tag(), iptcKey.record());
Expand Down Expand Up @@ -133,7 +133,7 @@ void processModify(const std::string& line, int num, IptcData& iptcData) {

std::string data(line.substr(dataStart));
// if data starts and ends with quotes, remove them
if (data.at(0) == '\"' && data.at(data.size() - 1) == '\"') {
if (data.front() == '\"' && data.back() == '\"') {
data = data.substr(1, data.size() - 2);
}
TypeId type = IptcDataSets::dataSetType(iptcKey.tag(), iptcKey.record());
Expand Down
6 changes: 3 additions & 3 deletions src/basicio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ int FileIo::Impl::switchMode(OpMode opMode) {
case opRead:
// Flush if current mode allows reading, else reopen (in mode "r+b"
// as in this case we know that we can write to the file)
if (openMode_.at(0) == 'r' || openMode_.at(1) == '+')
if (openMode_.front() == 'r' || openMode_.at(1) == '+')
reopen = false;
break;
case opWrite:
// Flush if current mode allows writing, else reopen
if (openMode_.at(0) != 'r' || openMode_.at(1) == '+')
if (openMode_.front() != 'r' || openMode_.at(1) == '+')
reopen = false;
break;
case opSeek:
Expand Down Expand Up @@ -499,7 +499,7 @@ size_t FileIo::tell() const {

size_t FileIo::size() const {
// Flush and commit only if the file is open for writing
if (p_->fp_ && (p_->openMode_.at(0) != 'r' || p_->openMode_.at(1) == '+')) {
if (p_->fp_ && (p_->openMode_.front() != 'r' || p_->openMode_.at(1) == '+')) {
std::fflush(p_->fp_);
#ifdef _MSC_VER
// This is required on msvcrt before stat after writing to a file
Expand Down
4 changes: 2 additions & 2 deletions src/sigmamn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ std::ostream& SigmaMakerNote::printStripLabel(std::ostream& os, const Value& val
}

std::ostream& SigmaMakerNote::print0x0008(std::ostream& os, const Value& value, const ExifData*) {
switch (value.toString().at(0)) {
switch (value.toString().front()) {
case 'P':
os << _("Program");
break;
Expand All @@ -103,7 +103,7 @@ std::ostream& SigmaMakerNote::print0x0008(std::ostream& os, const Value& value,
}

std::ostream& SigmaMakerNote::print0x0009(std::ostream& os, const Value& value, const ExifData*) {
switch (value.toString().at(0)) {
switch (value.toString().front()) {
case 'A':
os << _("Average");
break;
Expand Down
2 changes: 1 addition & 1 deletion src/tiffvisitor_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ void TiffDecoder::decodeCanonAFInfo(const TiffEntryBase* object) {
uint.push_back(static_cast<uint16_t>(object->pValue()->toInt64(i)));
}
// Check this is AFInfo2 (ints[0] = bytes in object)
if (ints.at(0) != static_cast<int16_t>(object->pValue()->count()) * 2)
if (ints.front() != static_cast<int16_t>(object->pValue()->count()) * 2)
return;

std::string familyGroup(std::string("Exif.") + groupName(object->group()) + ".");
Expand Down

0 comments on commit d7ac558

Please sign in to comment.