Showing the changes to src/core/util_string.cpp (1 of 3 files). Show all
Unified · Split
| @@ -495,7 +495,7 @@ std::string get_full_path( const std::string & fp ) · 494 unmodified lines | |||
| 495 | char * result = realpath(fp.c_str(), buf); | 495 | char * result = realpath(fp.c_str(), buf); |
| 496 | 496 | ||
| 497 | // try with .ck extension | 497 | // try with .ck extension |
| 498 | if(result == NULL && !str_endsin(fp.c_str(), ".ck")) | 498 | if( result == NULL && !extension_matches(fp, ".ck") ) |
| 499 | result = realpath((fp + ".ck").c_str(), buf); | 499 | result = realpath((fp + ".ck").c_str(), buf); |
| 500 | 500 | ||
| 501 | if(result == NULL) | 501 | if(result == NULL) |
| @@ -514,7 +514,7 @@ std::string get_full_path( const std::string & fp ) · 12 unmodified lines | |||
| 514 | #endif | 514 | #endif |
| 515 | 515 | ||
| 516 | // try with .ck extension | 516 | // try with .ck extension |
| 517 | if(result == 0 && !str_endsin(fp.c_str(), ".ck")) | 517 | if( result == 0 && !extension_matches(fp, ".ck") ) |
| 518 | { | 518 | { |
| 519 | #ifndef __CHUNREAL_ENGINE__ | 519 | #ifndef __CHUNREAL_ENGINE__ |
| 520 | result = GetFullPathName((fp + ".ck").c_str(), MAX_PATH, buf, NULL); | 520 | result = GetFullPathName((fp + ".ck").c_str(), MAX_PATH, buf, NULL); |
| @@ -687,21 +687,6 @@ std::string normalize_directory_separator( const std::string & filepath ) · 166 unmodified lines | |||
| 687 | 687 | ||
| 688 | 688 | ||
| 689 | 689 | ||
| 690 | //----------------------------------------------------------------------------- | ||
| 691 | // name: str_endsin() | ||
| 692 | // desc: return true if the first string ends with the second | ||
| 693 | //----------------------------------------------------------------------------- | ||
| 694 | t_CKBOOL str_endsin( const char * str, const char * end ) | ||
| 695 | { | ||
| 696 | size_t len = strlen(str); | ||
| 697 | size_t endlen = strlen(end); | ||
| 698 | |||
| 699 | return strncmp(str+(len-endlen), end, endlen) == 0; | ||
| 700 | } | ||
| 701 | |||
| 702 | |||
| 703 | |||
| 704 | |||
| 705 | //----------------------------------------------------------------------------- | 690 | //----------------------------------------------------------------------------- |
| 706 | // name: is_absolute_path() | 691 | // name: is_absolute_path() |
| 707 | // desc: return true if path names an absolute path on the underlying platform | 692 | // desc: return true if path names an absolute path on the underlying platform |
| @@ -730,23 +715,85 @@ t_CKBOOL is_absolute_path( const std::string & path ) · 22 unmodified lines | |||
| 730 | 715 | ||
| 731 | //----------------------------------------------------------------------------- | 716 | //----------------------------------------------------------------------------- |
| 732 | // name: extension_matches() | 717 | // name: extension_matches() |
| 733 | // desc: check whether a filename matches a particular extension | 718 | // desc: test whether a filename ends in a particular extension |
| 734 | //----------------------------------------------------------------------------- | 719 | //----------------------------------------------------------------------------- |
| 735 | t_CKBOOL extension_matches( const std::string & filename, const std::string & extension ) | 720 | t_CKBOOL extension_matches( const std::string & filename, |
| 721 | const std::string & extension, | ||
| 722 | t_CKBOOL ignoreCase ) | ||
| 736 | { | 723 | { |
| 737 | // lowercase | 724 | // if ignore case, lower case both |
| 738 | string f = tolower( filename ); | 725 | string f = ignoreCase ? tolower(filename) : filename; |
| 739 | string e = tolower( extension ); | 726 | string e = ignoreCase ? tolower(extension) : extension; |
| 740 | // look for extension from the end | 727 | // look for extension from the end |
| 741 | std::size_t pos = f.rfind( e ); | 728 | std::size_t pos = f.rfind( e ); |
| 742 | // check result | 729 | // check result |
| 743 | return (pos != std::string::npos) && (pos == (f.length()-e.length())); | 730 | return (pos != std::string::npos) && (pos == (f.length()-e.length())); |
| 731 | } | ||
| 732 | |||
| 733 | |||
| 744 | 734 | ||
| 745 | // t_CKUINT extension_length = strlen( extension ); | 735 | |
| 746 | // t_CKUINT filename_length = strlen( filename ); | 736 | //----------------------------------------------------------------------------- |
| 747 | // | 737 | // name: extension_removed() |
| 748 | // return strncmp( extension, filename+(filename_length-extension_length), | 738 | // desc: return filename without extension |
| 749 | // extension_length ) == 0; | 739 | //----------------------------------------------------------------------------- |
| 740 | std::string extension_removed( const std::string & filename, | ||
| 741 | const std::string & extension, | ||
| 742 | t_CKBOOL ignoreCase ) | ||
| 743 | { | ||
| 744 | // if ignore case, lower case both | ||
| 745 | string f = ignoreCase ? tolower(filename) : filename; | ||
| 746 | string e = ignoreCase ? tolower(extension) : extension; | ||
| 747 | // look for extension from the end | ||
| 748 | std::size_t pos = f.rfind( e ); | ||
| 749 | // no match, return original | ||
| 750 | if( pos == std::string::npos ) return filename; | ||
| 751 | // return substring | ||
| 752 | return filename.substr( 0, pos ); | ||
| 753 | } | ||
| 754 | |||
| 755 | |||
| 756 | |||
| 757 | |||
| 758 | //----------------------------------------------------------------------------- | ||
| 759 | // name: subdir_ok2recurse() | ||
| 760 | // desc: test if a directory name is OK to recurse, e.g., in search for chugins | ||
| 761 | // the reason we have this function is for macOS bundles that are actually | ||
| 762 | // directories, e.g., if Faust.chug is directory and the actual chugin | ||
| 763 | // is located in side in /Contents/MacOS -- in which case we would not | ||
| 764 | // search for more chugins within the Faust.chug directory; | ||
| 765 | // HOWEVER, something like .chug (a directory name starting with '.') is | ||
| 766 | // okay, as that could be hidden directory | ||
| 767 | //----------------------------------------------------------------------------- | ||
| 768 | t_CKBOOL subdir_ok2recurse( const std::string & dirName, | ||
| 769 | const std::string & extension, | ||
| 770 | t_CKBOOL ignoreCase ) | ||
| 771 | { | ||
| 772 | // if ignore case, lower case both | ||
| 773 | string f = ignoreCase ? tolower(dirName) : dirName; | ||
| 774 | string e = ignoreCase ? tolower(extension) : extension; | ||
| 775 | // if the two are equal, e.g., ".chug". OK | ||
| 776 | if( f == e ) return TRUE; | ||
| 777 | |||
| 778 | // return the opposite of extension matches | ||
| 779 | // i.e., if extension matches, don't recurse | ||
| 780 | return !extension_matches( dirName, extension, ignoreCase ); | ||
| 781 | } | ||
| 782 | |||
| 783 | |||
| 784 | |||
| 785 | |||
| 786 | //----------------------------------------------------------------------------- | ||
| 787 | // name: str_endsin() | ||
| 788 | // desc: return true if the first string ends with the second | ||
| 789 | // *** CURRENTLY NOT USED; see extension_matches() *** | ||
| 790 | //----------------------------------------------------------------------------- | ||
| 791 | t_CKBOOL str_endsin( const char * str, const char * end ) | ||
| 792 | { | ||
| 793 | size_t len = strlen(str); | ||
| 794 | size_t endlen = strlen(end); | ||
| 795 | |||
| 796 | return strncmp(str+(len-endlen), end, endlen) == 0; | ||
| 750 | } | 797 | } |
| 751 | 798 | ||
| 752 | 799 | ||