pizheng / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

fixCase for enum with underscore gives compilation error when used as default #142

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Define an enum item in the proto the Google naming guidelines, e.g. 
"RESOURCE_LIBRARY",
2. The enum item gets generated as "RESOURCELIBRARY" in the enum type,
3. Fields of that type have their default set to the name as defined in the 
proto file, e.g. "RESOURCE_LIBRARY".

What is the expected output? What do you see instead?
Preferably, the name as defined in the proto file should be kept unchanged 
because fixCase does not make them camel case. At the very least, the names 
used must be consistent.

What version of the product are you using? On what operating system?
1.0.0.280

Please provide any additional information below.

Original issue reported on code.google.com by pvginkel on 20 Nov 2010 at 2:06

GoogleCodeExporter commented 9 years ago
This only seems to happen if you in addition specify -p fixcase

Original comment by r...@raybooysen.com on 19 Jul 2012 at 1:38

GoogleCodeExporter commented 9 years ago
See fix for 167

Original comment by mAbushar...@hotmail.com on 12 Jun 2013 at 2:54

GoogleCodeExporter commented 9 years ago
You can make it actual create PascalCase if you modify the common.xslt 
toPascalCase template as below. Creating the val intermediate to detect the all 
uppercase scenario. Requires the fix described in 167 to work properly as well.

  <xsl:template name="toPascalCase">
    <xsl:param name="value"/>
    <xsl:param name="delimiter" select="'_'"/>
    <xsl:param name="keepDelimiter" select="false()"/>
    <xsl:if test="$value != ''">
      <xsl:variable name="val">
        <xsl:choose>
          <xsl:when test="$value=translate($value,$alpha,$ALPHA)">
            <xsl:value-of select="translate($value,$ALPHA,$alpha)"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$value"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:variable name="segment" select="substring-before($val, $delimiter)"/>
      <xsl:choose>
        <xsl:when test="$segment != ''">
          <xsl:value-of select="translate(substring($segment,1,1),$alpha,$ALPHA)"/><xsl:value-of select="substring($segment,2)"/><xsl:if test="$keepDelimiter"><xsl:value-of select="$delimiter"/></xsl:if>
          <xsl:call-template name="toPascalCase">
            <xsl:with-param name="value" select="substring-after($val, $delimiter)"/>
            <xsl:with-param name="delimiter" select="$delimiter"/>
            <xsl:with-param name="keepDelimiter" select="$keepDelimiter"/>
          </xsl:call-template>    
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="translate(substring($val,1,1),$alpha,$ALPHA)"/><xsl:value-of select="substring($val,2)"/>
        </xsl:otherwise>
      </xsl:choose>      
    </xsl:if>
  </xsl:template>

Original comment by Park.Ves...@gmail.com on 5 Sep 2013 at 6:18