utilities.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. function str_replace_word ($needle, $replacement, $haystack) {
  3. $pattern = "/\b$needle\b/";
  4. $haystack = preg_replace($pattern, $replacement, $haystack);
  5. return $haystack;
  6. }
  7. function istr_replace_word ($needle, $replacement, $haystack) {
  8. $pattern = "/\b$needle\b/i";
  9. $haystack = preg_replace($pattern, $replacement, $haystack);
  10. return $haystack;
  11. }
  12. function strtolowerref(&$str) {
  13. $str = strtolower($str);
  14. }
  15. // converts "STR_XX_YY_ZZ" to "Str Xx Yy Zz"
  16. function DeprecatedMacroToDirective($str) {
  17. // AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4 etc
  18. if (preg_match("!DEPRECATED_(IN_.*VERSION_.*)_AND_LATER!", $str, $matches)) {
  19. $str = strtolower($matches[1]);
  20. // cleanup
  21. $str = preg_replace("!in_mac_os_x_version_!", "in Mac OS X ", $str);
  22. $str = preg_replace("!([0-9])_([0-9])!e", '\1.\2', $str);
  23. return " deprecated '" . $str . " and later'";
  24. // NS_DEPRECATED(__MAC_10_1,__MAC_10_6,__IPHONE_NA,__IPHONE_NA),
  25. // __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_1,__MAC_10_6,__IPHONE_NA,__IPHONE_NA,
  26. // NS_DEPRECATED_IPHONE(__IPHONE_2_0,__IPHONE_2_0),
  27. // NS_DEPRECATED_MAC(__MAC_10_1, __MAC_10_5)
  28. } elseif (preg_match("!DEPRECATED(_IPHONE|_MAC)?\(([^)]+)\)!", $str, $matches)) {
  29. $str = strtolower($matches[2]);
  30. $versions = preg_replace("!__MAC_!e", "Mac OS X ", $str);
  31. $versions = preg_replace("!__IPHONE_!e", "iOS ", $versions);
  32. $versions = preg_replace("!([0-9])_([0-9])!e", '\1.\2', $versions);
  33. $deprecatedversions = explode(",", $matches[2]);
  34. $result = "";
  35. if ($matches[1] == "") {
  36. $macindex = 2;
  37. $iphoneindex = 4;
  38. } elseif ($matches[1] == "_IPHONE") {
  39. $macindex = -1;
  40. $iphoneindex = 2;
  41. } else {
  42. $macindex = 2;
  43. $iphoneindex = -1;
  44. }
  45. if (($macindex != -1) && !preg_match("!Mac OS X( Version)? NA|MAC_NA!", $deprecatedversions[$macindex])) {
  46. $result = "in " . $deprecatedversions[$macindex] . " and later";
  47. }
  48. if (($iphoneindex != -1) && !preg_match("!iOS( Version)? NA|IPHONE_NA!", $deprecatedversions[$iphoneindex])) {
  49. if ($result != "") $result .= ", ";
  50. $result .= "in " . $deprecatedversions[$iphoneindex] . " and later";
  51. }
  52. return " deprecated '" . $result . "'";
  53. }
  54. }
  55. ?>