Changeset 5331


Ignore:
Timestamp:
08/17/10 17:09:13 (15 years ago)
Author:
Eric.Larour
Message:

Better isdistributed, look from the end of the string
backwards. This avoids descriptors like rheology_B2d1 to be
cut to rheology_B

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/shared/String/isdistributed.cpp

    r3332 r5331  
    2525        char* root=NULL;
    2626
    27         /*intermediary: */
    28         for(i=0;i<strlen(name);i++){
    29                 if (isdigit(name[i])){
    30                         distributed=1;
    31                         break;
    32                 }
    33         }
     27        /*Look at the end of the string, whether it's numeric or not: */
     28        if (isdigit(name[strlen(name)-1]))distributed=1;
    3429
    3530        if(distributed){
     31               
    3632                root=(char*)xmalloc((strlen(name)+1)*sizeof(char));
    3733                strcpy(root,name);
    3834       
    39                 for(i=0;i<strlen(name);i++){
     35                /*Start from the end, until we find a letter, which we will, otherwise error out: */
     36                for(i=strlen(name)-1;i>=0;i++){
    4037                        if (isdigit(name[i])){
    41                                 root[i]='\0'; //finish the string here.
    42                                 break;
     38                                root[i]='\0'; //finish the string here and keep looking for a letter
    4339                        }
     40                        else break;
    4441                }
    4542        }
Note: See TracChangeset for help on using the changeset viewer.