| 117 | } |
| 118 | |
| 119 | cv::string cv::FileStorage::getDefaultObjectName(const string& _filename) |
| 120 | { |
| 121 | static const char* stubname = "unnamed"; |
| 122 | const char* filename = _filename.c_str(); |
| 123 | const char* ptr2 = filename + _filename.size(); |
| 124 | const char* ptr = ptr2 - 1; |
| 125 | cv::AutoBuffer<char> name_buf(_filename.size()+1); |
| 126 | |
| 127 | while( ptr >= filename && *ptr != '\\' && *ptr != '/' && *ptr != ':' ) |
| 128 | { |
| 129 | if( *ptr == '.' && (!*ptr2 || strncmp(ptr2, ".gz", 3) == 0) ) |
| 130 | ptr2 = ptr; |
| 131 | ptr--; |
| 132 | } |
| 133 | ptr++; |
| 134 | if( ptr == ptr2 ) |
| 135 | CV_Error( CV_StsBadArg, "Invalid filename" ); |
| 136 | |
| 137 | char* name = name_buf; |
| 138 | |
| 139 | // name must start with letter or '_' |
| 140 | if( !cv_isalpha(*ptr) && *ptr!= '_' ){ |
| 141 | *name++ = '_'; |
| 142 | } |
| 143 | |
| 144 | while( ptr < ptr2 ) |
| 145 | { |
| 146 | char c = *ptr++; |
| 147 | if( !cv_isalnum(c) && c != '-' && c != '_' ) |
| 148 | c = '_'; |
| 149 | *name++ = c; |
| 150 | } |
| 151 | *name = '\0'; |
| 152 | name = name_buf; |
| 153 | if( strcmp( name, "_" ) == 0 ) |
| 154 | strcpy( name, stubname ); |
| 155 | return cv::string(name); |
| 156 | } |
| 157 | |
| 158 | namespace cv |
| 159 | { |
nothing calls this directly
no test coverage detected