Skip to content

Commit

Permalink
some optimizations for #495
Browse files Browse the repository at this point in the history
  • Loading branch information
darkv committed Jan 16, 2014
1 parent 0591ed3 commit 71c64c2
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2052,24 +2052,27 @@ public static synchronized NSArray stringAttributeListForEntityNamed(EOEditingCo
}

/**
* Trims all values from string attributes from the given EO.
* @param object
* Trims all values from string attributes from the given EO unless the EO itself
* or the string attribute is flagged as read-only.
*
* @param object the EO whose string attributes should be trimmed
*/
public static void trimSpaces(EOEnterpriseObject object) {
EOEntity entity = EOUtilities.entityForObject(object.editingContext(), object);
if (entity.isReadOnly()) {
return;
}
for (Enumeration e=ERXEOControlUtilities.stringAttributeListForEntityNamed(object.editingContext(), object.entityName()).objectEnumerator(); e.hasMoreElements();) {
String key=(String)e.nextElement();
String value=(String)object.storedValueForKey(key);
if (value!=null) {
if (!EOUtilities.entityForObject(object.editingContext(), object).isReadOnly() &&
!EOUtilities.entityForObject(object.editingContext(), object).attributeNamed(key).isReadOnly()) {
String trimmedValue=value.trim();
if (trimmedValue.length()!=value.length())
object.takeStoredValueForKey(trimmedValue,key);
}
if (value != null && !entity.attributeNamed(key).isReadOnly()) {
String trimmedValue=value.trim();
if (trimmedValue.length()!=value.length())
object.takeStoredValueForKey(trimmedValue,key);
}
}
}

/**
* Convenience to get the destination entity name from a key path of an object.
* Returns null if no destination found.
Expand Down

0 comments on commit 71c64c2

Please sign in to comment.