Advertisement
A_GUES

C++ AdBlocker

May 30th, 2023 (edited)
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <regex>
  5.  
  6. // Function to check if a URL should be blocked
  7. bool shouldBlockURL(const std::string& url) {
  8.     // Define your rules for blocking URLs using regular expressions
  9.     std::regex adRegex(".*ad\\.com.*");
  10.     std::regex spamRegex(".*spam\\.com.*");
  11.  
  12.     // Check if the URL matches any of the blocking rules
  13.     if (std::regex_match(url, adRegex) || std::regex_match(url, spamRegex)) {
  14.         return true;
  15.     }
  16.    
  17.     return false;
  18. }
  19.  
  20. int main() {
  21.     // Read the URLs from a file
  22.     std::ifstream file("urls.txt");
  23.     if (!file) {
  24.         std::cerr << "Failed to open the file." << std::endl;
  25.         return 1;
  26.     }
  27.  
  28.     std::string url;
  29.     while (std::getline(file, url)) {
  30.         // Check if the URL should be blocked
  31.         if (shouldBlockURL(url)) {
  32.             std::cout << "Blocked URL: " << url << std::endl;
  33.             // You can perform additional actions here, such as hiding the ad or logging the blocked URLs.
  34.         } else {
  35.             std::cout << "Allowed URL: " << url << std::endl;
  36.         }
  37.     }
  38.  
  39.     file.close();
  40.    
  41.     return 0;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement