[c/c++]_[determines if the file name suffix is the fastest format supported]

Source: Internet
Author: User


Scene:

1. You already know that a library supports only a few image formats, Png,jpg,gif,bmp,tif,jpeg. Now when you load the file, you should determine if the file suffix name is the above supported format.

2. In general, it is not in the list that is supported, but it is necessary to iterate over multiple judgments.


Solution:

1. Find out through find by constructing a specific string structure. --- if there is a faster trouble to tell me, did not refer to the implementation of open source code, estimates should have.

"; jpg;png;bmp;jpeg;gif;"

Main.cpp


#include <iostream> #include <algorithm> #include <string.h> #include <assert.h>std::string Getfileposfix (const char* path) {char* pos = strrchr (Path, '. '); if (POS) {std::string str (pos+1);//1. Convert to lowercase//http://blog.csdn.net/infoworld/article/details/29872869std::transform (Str.begin (), Str.end (), Str.begin (),:: ToLower); return str;} return std::string ();} BOOL Issupportpos (const std::string& posfix,const std::string& support) {std::string str (";"); Str.append (Posfix). Append (";"); if (Support.find (str)!=std::string::npos) {return true;} return false;} int main (int argc, char const *argv[]) {Const char* posfix = "; jpg;png;bmp;jpeg;gif;"; Const char* Path = "E:\\picture\\11.ggif"; std::string posfix = Getfileposfix (path); std::cout << Posfix << std :: Endl;assert (! Issupportpos (posfix,posfix));p ath = "E:\\picture\\11.gif";p osfix = getfileposfix (path); Std::cout << Posfix < < Std::endl;assert (Issupportpos (Posfix,posfix)); return 0;}



[c/c++]_[determines if the file name suffix is the fastest format supported]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.