12 return std::string(
"");
15 const std::string months[] = {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
16 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"};
21 std::string day = httpDate.substr(5, 2);
22 t.tm_mday = std::stoi(day);
25 std::string monthStr = httpDate.substr(8, 3);
27 for (
int i = 0; i < 12; i++)
29 if (months[i] == monthStr)
36 if (monthIndex >= 0 && monthIndex <= 11)
38 t.tm_mon = monthIndex;
42 std::string year = httpDate.substr(12, 4);
43 t.tm_year = std::stoi(year) - 1900;
46 std::string time = httpDate.substr(17, 8);
47 std::string hour = time.substr(0, 2);
48 std::string min = time.substr(3, 2);
49 std::string sec = time.substr(6, 2);
51 t.tm_hour = std::stoi(hour);
52 t.tm_min = std::stoi(min);
53 t.tm_sec = std::stoi(sec);
57 ss << std::put_time(&t,
"%FT%TZ");
64 auto segments = StringArray::fromTokens(p,
",.",
"");
66 segments.removeEmptyStrings();
73 if (segments.size() == 2)
75 value = (segments[0].getIntValue() << 8) + segments[1].getIntValue();
79 value = (segments[0].getIntValue() << 16) + (segments[1].getIntValue() << 8) +
80 segments[2].getIntValue();
91 static bool compareFloats(
const float& a,
const float& b) {
return a < b; }
100 float widthMax =
static_cast<float>(maxWidth);
102 Array<float> xOffsets;
103 font.getGlyphPositions(input, glyphs, xOffsets);
104 float inputStringWidth = xOffsets.getLast();
106 if (inputStringWidth <= widthMax)
110 const String ellipsis =
"...";
111 const float ellipsisWidth = font.getStringWidthFloat(ellipsis);
112 const float halfStringWidth = (widthMax - ellipsisWidth) * 0.5f;
113 const float startOfSecondHalf = inputStringWidth - halfStringWidth;
117 const int indexEndOfFirstHalf =
static_cast<int>(
118 std::lower_bound(xOffsets.begin(), xOffsets.end(), halfStringWidth, &
compareFloats) -
121 const int indexStartOfSecondHalf =
static_cast<int>(
122 std::lower_bound(xOffsets.begin(), xOffsets.end(), startOfSecondHalf, &
compareFloats) -
125 return input.substring(0, indexEndOfFirstHalf - 1) + ellipsis +
126 input.substring(indexStartOfSecondHalf, input.length());
131 String result = inputPath;
133 if (inputPath.containsChar(
'/'))
136 result = inputPath.replaceCharacter(
'/',
'\\');
139 if (inputPath.containsChar(
'\\'))
142 result = inputPath.replaceCharacter(
'\\',
'/');
151 if (!std::all_of(input.begin(), input.end(), [](
unsigned char c){ return std::isxdigit(c); }))
153 throw std::invalid_argument(
"Input string contains invalid hexadecimal characters.");
158 byteArray.resize((input.length() % 2 != 0 ? input.length() + 1 : input.length()) / 2);
160 for (
size_t i = 0, j = 0; i < input.length(); i += 2, j++)
163 std::string byteStr = i + 1 < input.length() ? input.substr(i, 2) : input.substr(i, 1) +
"0";
164 unsigned int byteValue;
165 std::istringstream(byteStr) >> std::hex >> byteValue;
166 byteArray[j] =
static_cast<unsigned char>(byteValue);
int getVersionAsHexInteger(StringRef versionString)
Definition helpers.cpp:86
void hexStringToByteArray(const std::string &input, std::vector< unsigned char > &byteArray)
Converts a hex string to a byte array.
Definition helpers.cpp:148
StringArray getVersionSegments(StringRef p)
Definition helpers.cpp:62
std::string HttpDateToISO8601(const std::string &httpDate)
Converts a date from HTTP-Date to ISO8601 format.
Definition helpers.cpp:5
static bool compareFloats(const float &a, const float &b)
Definition helpers.cpp:91
int getVersionAsHexIntegerFromParts(const StringArray &segments)
Definition helpers.cpp:70
String convertFilePathString(const String &inputPath)
Converts a file path passed as a raw string, to the current platform. Has no effect if the path is al...
Definition helpers.cpp:129
String ellipsizeStringToWidth(const Font &font, const String &input, const int maxWidth)
Cuts the center out of a String to make it fit a given pixel width.
Definition helpers.cpp:93
Definition AirAbsorptionFilter.cpp:2