rename methods to make the difference between field end (exclusive) and field end mark offset (inclusive)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1147134 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sergey Vladimirov 2011-07-15 12:58:14 +00:00
parent 285ee2ad58
commit 86988f78de
3 changed files with 94 additions and 64 deletions

View File

@ -118,7 +118,7 @@ public abstract class AbstractWordConverter
processField( ( (HWPFDocument) hwpfDocument ), range, processField( ( (HWPFDocument) hwpfDocument ), range,
currentTableLevel, aliveField, block ); currentTableLevel, aliveField, block );
int continueAfter = aliveField.getEndOffset(); int continueAfter = aliveField.getFieldEndOffset();
while ( c < range.numCharacterRuns() while ( c < range.numCharacterRuns()
&& range.getCharacterRun( c ).getEndOffset() <= continueAfter ) && range.getCharacterRun( c ).getEndOffset() <= continueAfter )
c++; c++;
@ -445,7 +445,7 @@ public abstract class AbstractWordConverter
currentBlock ); currentBlock );
if ( possibleField != null ) if ( possibleField != null )
{ {
c = possibleField.getEndOffset(); c = possibleField.getFieldEndOffset();
} }
else else
{ {

View File

@ -4,9 +4,9 @@ import org.apache.poi.hwpf.usermodel.Range;
public class Field public class Field
{ {
private PlexOfField startPlex;
private PlexOfField separatorPlex;
private PlexOfField endPlex; private PlexOfField endPlex;
private PlexOfField separatorPlex;
private PlexOfField startPlex;
public Field( PlexOfField startPlex, PlexOfField separatorPlex, public Field( PlexOfField startPlex, PlexOfField separatorPlex,
PlexOfField endPlex ) PlexOfField endPlex )
@ -34,12 +34,42 @@ public class Field
this.endPlex = endPlex; this.endPlex = endPlex;
} }
public int getStartOffset() public Range firstSubrange( Range parent )
{ {
return startPlex.getFcStart(); if ( hasSeparator() )
{
if ( getMarkStartOffset() + 1 == getMarkSeparatorOffset() )
return null;
return new Range( getMarkStartOffset() + 1,
getMarkSeparatorOffset(), parent )
{
@Override
public String toString()
{
return "FieldSubrange1 (" + super.toString() + ")";
}
};
}
if ( getMarkStartOffset() + 1 == getMarkEndOffset() )
return null;
return new Range( getMarkStartOffset() + 1, getMarkEndOffset(), parent )
{
@Override
public String toString()
{
return "FieldSubrange1 (" + super.toString() + ")";
}
};
} }
public int getEndOffset() /**
* @return character position of first character after field (i.e.
* {@link #getMarkEndOffset()} + 1)
*/
public int getFieldEndOffset()
{ {
/* /*
* sometimes plex looks like [100, 2000), where 100 is the position of * sometimes plex looks like [100, 2000), where 100 is the position of
@ -49,24 +79,68 @@ public class Field
return endPlex.getFcStart() + 1; return endPlex.getFcStart() + 1;
} }
public boolean hasSeparator() /**
* @return character position of first character in field (i.e.
* {@link #getFieldStartOffset()})
*/
public int getFieldStartOffset()
{ {
return separatorPlex != null; return startPlex.getFcStart();
} }
public int getSeparatorOffset() /**
* @return character position of end field mark
*/
public int getMarkEndOffset()
{
return endPlex.getFcStart();
}
/**
* @return character position of separator field mark (if present,
* {@link NullPointerException} otherwise)
*/
public int getMarkSeparatorOffset()
{ {
return separatorPlex.getFcStart(); return separatorPlex.getFcStart();
} }
/**
* @return character position of start field mark
*/
public int getMarkStartOffset()
{
return startPlex.getFcStart();
}
public int getType() public int getType()
{ {
return startPlex.getFld().getFieldType(); return startPlex.getFld().getFieldType();
} }
public boolean isZombieEmbed() public boolean hasSeparator()
{ {
return endPlex.getFld().isFZombieEmbed(); return separatorPlex != null;
}
public boolean isHasSep()
{
return endPlex.getFld().isFHasSep();
}
public boolean isLocked()
{
return endPlex.getFld().isFLocked();
}
public boolean isNested()
{
return endPlex.getFld().isFNested();
}
public boolean isPrivateResult()
{
return endPlex.getFld().isFPrivateResult();
} }
public boolean isResultDirty() public boolean isResultDirty()
@ -79,63 +153,19 @@ public class Field
return endPlex.getFld().isFResultEdited(); return endPlex.getFld().isFResultEdited();
} }
public boolean isLocked() public boolean isZombieEmbed()
{ {
return endPlex.getFld().isFLocked(); return endPlex.getFld().isFZombieEmbed();
}
public boolean isPrivateResult()
{
return endPlex.getFld().isFPrivateResult();
}
public boolean isNested()
{
return endPlex.getFld().isFNested();
}
public boolean isHasSep()
{
return endPlex.getFld().isFHasSep();
}
public Range firstSubrange( Range parent )
{
if ( hasSeparator() )
{
if ( getStartOffset() + 1 == getSeparatorOffset() )
return null;
return new Range( getStartOffset() + 1, getSeparatorOffset(),
parent )
{
@Override
public String toString()
{
return "FieldSubrange1 (" + super.toString() + ")";
}
};
}
if ( getStartOffset() + 1 == getEndOffset() )
return null;
return new Range( getStartOffset() + 1, getEndOffset(), parent )
{
@Override
public String toString()
{
return "FieldSubrange1 (" + super.toString() + ")";
}
};
} }
public Range secondSubrange( Range parent ) public Range secondSubrange( Range parent )
{ {
if ( !hasSeparator() || getSeparatorOffset() + 1 == getEndOffset() ) if ( !hasSeparator()
|| getMarkSeparatorOffset() + 1 == getMarkEndOffset() )
return null; return null;
return new Range( getSeparatorOffset() + 1, getEndOffset(), parent ) return new Range( getMarkSeparatorOffset() + 1, getMarkEndOffset(),
parent )
{ {
@Override @Override
public String toString() public String toString()
@ -148,7 +178,7 @@ public class Field
@Override @Override
public String toString() public String toString()
{ {
return "Field [" + getStartOffset() + "; " + getEndOffset() return "Field [" + getFieldStartOffset() + "; " + getFieldEndOffset()
+ "] (type: 0x" + Integer.toHexString( getType() ) + " = " + "] (type: 0x" + Integer.toHexString( getType() ) + " = "
+ getType() + " )"; + getType() + " )";
} }

View File

@ -114,7 +114,7 @@ public class FieldsTables
fields.size() ); fields.size() );
for ( Field field : fields ) for ( Field field : fields )
{ {
result.put( Integer.valueOf( field.getStartOffset() ), field ); result.put( Integer.valueOf( field.getFieldStartOffset() ), field );
} }
return result; return result;
} }