MCPcopy Create free account
hub / github.com/bewuethr/stroustrup-ppp / get_encoding

Function get_encoding

chapter22/chapter22_Graph.cpp:696–719  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

694#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
695
696Suffix::Encoding get_encoding(const string& s)
697{
698 struct SuffixMap
699 {
700 const char* extension;
701 Suffix::Encoding suffix;
702 };
703
704 static SuffixMap smap[] = {
705 {".jpg", Suffix::jpg},
706 {".jpeg", Suffix::jpg},
707 {".gif", Suffix::gif},
708 };
709
710 for (int i = 0, n = ARRAY_SIZE(smap); i < n; i++)
711 {
712 int len = strlen(smap[i].extension);
713
714 if (s.length() >= len && s.substr(s.length()-len, len) == smap[i].extension)
715 return smap[i].suffix;
716 }
717
718 return Suffix::none;
719}
720
721//------------------------------------------------------------------------------
722

Callers 1

ImageMethod · 0.70

Calls 1

strlenFunction · 0.50

Tested by

no test coverage detected