1 /* 2 * Copyright (C) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "medialibrary_data_manager_utils.h" 17 18 #include "media_file_uri.h" 19 #include "media_file_utils.h" 20 #include "media_log.h" 21 #include "medialibrary_common_utils.h" 22 #include "medialibrary_db_const.h" 23 #include "photo_album_column.h" 24 25 using namespace std; 26 27 namespace OHOS { 28 namespace Media { IsNumber(const string & str)29bool MediaLibraryDataManagerUtils::IsNumber(const string &str) 30 { 31 if (str.empty()) { 32 MEDIA_ERR_LOG("IsNumber input is empty "); 33 return false; 34 } 35 36 for (char const &c : str) { 37 if (isdigit(c) == 0) { 38 return false; 39 } 40 } 41 return true; 42 } 43 GetOperationType(const string & uri)44string MediaLibraryDataManagerUtils::GetOperationType(const string &uri) 45 { 46 string oprn; 47 size_t found = uri.rfind('/'); 48 if (found != string::npos) { 49 oprn = uri.substr(found + 1); 50 } 51 52 return oprn; 53 } 54 GetIdFromUri(const string & uri)55string MediaLibraryDataManagerUtils::GetIdFromUri(const string &uri) 56 { 57 return MediaFileUri(uri).GetFileId(); 58 } 59 GetNetworkIdFromUri(const string & uri)60string MediaLibraryDataManagerUtils::GetNetworkIdFromUri(const string &uri) 61 { 62 return MediaFileUri(uri).GetNetworkId(); 63 } 64 GetDisPlayNameFromPath(const std::string & path)65string MediaLibraryDataManagerUtils::GetDisPlayNameFromPath(const std::string &path) 66 { 67 string displayName; 68 size_t lastSlashPosition = path.rfind("/"); 69 if (lastSlashPosition != string::npos) { 70 displayName = path.substr(lastSlashPosition + 1); 71 } 72 return displayName; 73 } 74 ObtionCondition(string & strQueryCondition,const vector<string> & whereArgs)75string MediaLibraryDataManagerUtils::ObtionCondition(string &strQueryCondition, const vector<string> &whereArgs) 76 { 77 for (string args : whereArgs) { 78 size_t pos = strQueryCondition.find('?'); 79 if (pos != string::npos) { 80 strQueryCondition.replace(pos, 1, "'" + args + "'"); 81 } 82 } 83 return strQueryCondition; 84 } 85 GetTypeUriByUri(std::string & uri)86std::string MediaLibraryDataManagerUtils::GetTypeUriByUri(std::string &uri) 87 { 88 string typeUri; 89 if (uri.find(PhotoColumn::PHOTO_URI_PREFIX) != string::npos) { 90 typeUri = PhotoColumn::PHOTO_URI_PREFIX; 91 } else if (uri.find(PhotoAlbumColumns::ALBUM_URI_PREFIX) != string::npos) { 92 typeUri = PhotoAlbumColumns::ALBUM_URI_PREFIX; 93 } else if (uri.find(AudioColumn::AUDIO_URI_PREFIX) != string::npos) { 94 typeUri = AudioColumn::AUDIO_URI_PREFIX; 95 } 96 return typeUri; 97 } 98 } // namespace Media 99 } // namespace OHOS 100