Permalink
Browse files

issue# (TFJ-734)

add getDescriptionURLEntities to LazyUser.
allow HTMLEntity.unescapeAndSlideEntityIncdices to accept null parameters.
  • Loading branch information...
1 parent 5789ab4 commit 6df5118daba41cdea7122eb84ef18ed507bc4717 @ApplePedlar ApplePedlar committed Dec 10, 2012
View
12 twitter4j-appengine/src/main/java/twitter4j/internal/json/LazyUser.java
@@ -101,7 +101,17 @@ public String getLocation() {
public String getDescription() {
return getTarget().getDescription();
}
-
+
+ /**
+ * Returns URL entities for user description.
+ *
+ * @return URL entities for user description
+ * @since Twitter4J 3.0.3
+ */
+ @Override
+ public URLEntity[] getDescriptionURLEntities() {
+ return getTarget().getDescriptionURLEntities();
+ }
/**
* Tests if the user is enabling contributors
View
35 twitter4j-core/src/main/java/twitter4j/internal/json/HTMLEntity.java
@@ -84,16 +84,33 @@ static void unescape(StringBuilder original) {
static String unescapeAndSlideEntityIncdices(String text, UserMentionEntity[] userMentionEntities,
URLEntity[] urlEntities, HashtagEntity[] hashtagEntities,
MediaEntity[] mediaEntities) {
- EntityIndex[] entityIndexes = new EntityIndex[userMentionEntities.length + urlEntities.length +
- hashtagEntities.length + mediaEntities.length];
+
+ int entityIndexesLength = 0;
+ entityIndexesLength += userMentionEntities == null ? 0 : userMentionEntities.length;
+ entityIndexesLength += urlEntities == null ? 0 : urlEntities.length;
+ entityIndexesLength += hashtagEntities == null ? 0 : hashtagEntities.length;
+ entityIndexesLength += mediaEntities == null ? 0 : mediaEntities.length;
+
+ EntityIndex[] entityIndexes = new EntityIndex[entityIndexesLength];
int copyStartIndex = 0;
- System.arraycopy(userMentionEntities, 0, entityIndexes, copyStartIndex, userMentionEntities.length);
- copyStartIndex += userMentionEntities.length;
- System.arraycopy(urlEntities, 0, entityIndexes, copyStartIndex, urlEntities.length);
- copyStartIndex += urlEntities.length;
- System.arraycopy(hashtagEntities, 0, entityIndexes, copyStartIndex, hashtagEntities.length);
- copyStartIndex += hashtagEntities.length;
- System.arraycopy(mediaEntities, 0, entityIndexes, copyStartIndex, mediaEntities.length);
+ if (userMentionEntities != null) {
+ System.arraycopy(userMentionEntities, 0, entityIndexes, copyStartIndex, userMentionEntities.length);
+ copyStartIndex += userMentionEntities.length;
+ }
+
+ if (urlEntities != null) {
+ System.arraycopy(urlEntities, 0, entityIndexes, copyStartIndex, urlEntities.length);
+ copyStartIndex += urlEntities.length;
+ }
+
+ if (hashtagEntities != null) {
+ System.arraycopy(hashtagEntities, 0, entityIndexes, copyStartIndex, hashtagEntities.length);
+ copyStartIndex += hashtagEntities.length;
+ }
+
+ if (mediaEntities != null) {
+ System.arraycopy(mediaEntities, 0, entityIndexes, copyStartIndex, mediaEntities.length);
+ }
Arrays.sort(entityIndexes);
boolean handlingStart = true;
View
3 twitter4j-core/src/main/java/twitter4j/internal/json/UserJSONImpl.java
@@ -126,8 +126,7 @@ private void init(JSONObject json) throws TwitterException {
description = getRawString("description", json);
if (description != null) {
description = HTMLEntity.unescapeAndSlideEntityIncdices(description,
- new UserMentionEntity[0], descriptionURLEntities,
- new HashtagEntity[0], new MediaEntity[0]);
+ null, descriptionURLEntities, null, null);
}
isContributorsEnabled = getBoolean("contributors_enabled", json);

0 comments on commit 6df5118

Please sign in to comment.