components/variations/service/generate_ui_string_overrider.py
def _GenerateSourceFileContent(resources_content, namespace, header_filename):
  """Generates the .cc content from the given generated grit headers content.

  Args:
    resources_content: The input string to process, contains lines of the form
        "#define NAME INDEX".

    namespace: The namespace in which the generated code should be scoped. If
        not defined, then the code will be in the global namespace.

    header_filename: Path to the corresponding .h.

  Returns:
    .cc file content implementing the CreateUIStringOverrider() factory.
  """
  hashed_tuples = _GetResourceListFromString(resources_content)

  collisions = _CheckForHashCollisions(hashed_tuples)
  if collisions:
    error_message = "\n".join(
        ["hash: %i, name: %s" % (i.hash, i.name) for i in sorted(collisions)])
    error_message = ("\nThe following names had hash collisions "
                     "(sorted by the hash value):\n%s\n" %(error_message))
    raise HashCollisionError(error_message)

  hashes_array = _GenDataArray(
      hashed_tuples, "    %iU,  // %s", 'kResourceHashes', 'uint32_t',
      operator.attrgetter('hash'))
  indices_array = _GenDataArray(
      hashed_tuples, "    %s,  // %s", 'kResourceIndices', 'int',
      operator.attrgetter('index'))

  namespace_prefix, namespace_suffix = _GenerateNamespacePrefixAndSuffix(
      namespace)

  return (
      "// This file was generated by %(script_name)s. Do not edit.\n"
      "\n"
      "#include \"%(header_filename)s\"\n\n"
      "%(namespace_prefix)s"
      "namespace {\n\n"
      "const size_t kNumResources = %(num_resources)i;\n\n"
      "%(hashes_array)s"
      "\n"
      "%(indices_array)s"
      "\n"
      "}  // namespace\n"
      "\n"
      "variations::UIStringOverrider CreateUIStringOverrider() {\n"
      "  return variations::UIStringOverrider(\n"
      "      kResourceHashes, kResourceIndices, kNumResources);\n"
      "}\n"
      "%(namespace_suffix)s") % {
          'script_name': SCRIPT_NAME,
          'header_filename': header_filename,
          'namespace_prefix': namespace_prefix,
          'num_resources': len(hashed_tuples),
          'hashes_array': hashes_array,
          'indices_array': indices_array,
          'namespace_suffix': namespace_suffix,
      }
Generates the .cc content from the given generated grit headers content.

  Args:
    resources_content: The input string to process, contains lines of the form
        "#define NAME INDEX".

    namespace: The namespace in which the generated code should be scoped. If
        not defined, then the code will be in the global namespace.

    header_filename: Path to the corresponding .h.

  Returns:
    .cc file content implementing the CreateUIStringOverrider() factory.
  
Generates the .cc content from the given generated grit headers content.
Generates the . cc content from the given generated grit headers content .
def _GenerateSourceFileContent(resources_content, namespace, header_filename):
  hashed_tuples = _GetResourceListFromString(resources_content)
  collisions = _CheckForHashCollisions(hashed_tuples)
  if collisions:
    error_message = "\n".join(
        ["hash: %i, name: %s" % (i.hash, i.name) for i in sorted(collisions)])
    error_message = ("\nThe following names had hash collisions "
                     "(sorted by the hash value):\n%s\n" %(error_message))
    raise HashCollisionError(error_message)
  hashes_array = _GenDataArray(
      hashed_tuples, "    %iU,  // %s", 'kResourceHashes', 'uint32_t',
      operator.attrgetter('hash'))
  indices_array = _GenDataArray(
      hashed_tuples, "    %s,  // %s", 'kResourceIndices', 'int',
      operator.attrgetter('index'))
  namespace_prefix, namespace_suffix = _GenerateNamespacePrefixAndSuffix(
      namespace)
  return (
      "// This file was generated by %(script_name)s. Do not edit.\n"
      "\n"
      "#include \"%(header_filename)s\"\n\n"
      "%(namespace_prefix)s"
      "namespace {\n\n"
      "const size_t kNumResources = %(num_resources)i;\n\n"
      "%(hashes_array)s"
      "\n"
      "%(indices_array)s"
      "\n"
      "}  // namespace\n"
      "\n"
      "variations::UIStringOverrider CreateUIStringOverrider() {\n"
      "  return variations::UIStringOverrider(\n"
      "      kResourceHashes, kResourceIndices, kNumResources);\n"
      "}\n"
      "%(namespace_suffix)s") % {
          'script_name': SCRIPT_NAME,
          'header_filename': header_filename,
          'namespace_prefix': namespace_prefix,
          'num_resources': len(hashed_tuples),
          'hashes_array': hashes_array,
          'indices_array': indices_array,
          'namespace_suffix': namespace_suffix,
      }
def _GenerateSourceFileContent ( resources_content , namespace , header_filename ) : hashed_tuples = _GetResourceListFromString ( resources_content ) collisions = _CheckForHashCollisions ( hashed_tuples ) if collisions : error_message = "\n" . join ( [ "hash: %i, name: %s" % ( i . hash , i . name ) for i in sorted ( collisions ) ] ) error_message = ( "\nThe following names had hash collisions " "(sorted by the hash value):\n%s\n" % ( error_message ) ) raise HashCollisionError ( error_message ) hashes_array = _GenDataArray ( hashed_tuples , "    %iU,  // %s" , 'kResourceHashes' , 'uint32_t' , operator . attrgetter ( 'hash' ) ) indices_array = _GenDataArray ( hashed_tuples , "    %s,  // %s" , 'kResourceIndices' , 'int' , operator . attrgetter ( 'index' ) ) namespace_prefix , namespace_suffix = _GenerateNamespacePrefixAndSuffix ( namespace ) return ( "// This file was generated by %(script_name)s. Do not edit.\n" "\n" "#include \"%(header_filename)s\"\n\n" "%(namespace_prefix)s" "namespace {\n\n" "const size_t kNumResources = %(num_resources)i;\n\n" "%(hashes_array)s" "\n" "%(indices_array)s" "\n" "}  // namespace\n" "\n" "variations::UIStringOverrider CreateUIStringOverrider() {\n" "  return variations::UIStringOverrider(\n" "      kResourceHashes, kResourceIndices, kNumResources);\n" "}\n" "%(namespace_suffix)s" ) % { 'script_name' : SCRIPT_NAME , 'header_filename' : header_filename , 'namespace_prefix' : namespace_prefix , 'num_resources' : len ( hashed_tuples ) , 'hashes_array' : hashes_array , 'indices_array' : indices_array , 'namespace_suffix' : namespace_suffix , }
Generates the .cc content from the given generated grit headers content.
Generates the . cc content from the given generated grit headers content .
"""Generates the .cc content from the given generated grit headers content.

  Args:
    resources_content: The input string to process, contains lines of the form
        "#define NAME INDEX".

    namespace: The namespace in which the generated code should be scoped. If
        not defined, then the code will be in the global namespace.

    header_filename: Path to the corresponding .h.

  Returns:
    .cc file content implementing the CreateUIStringOverrider() factory.
  """
.cc file content implementing the CreateUIStringOverrider() factory.
. cc file content implementing the CreateUIStringOverrider () factory .
resources_content
The input string to process, contains lines of the form
"#define NAME INDEX".
The input string to process contains lines of the form " #define NAME INDEX " .
namespace
The namespace in which the generated code should be scoped. If
not defined, then the code will be in the global namespace.
The namespace in which the generated code should be scoped . If not defined then the code will be in the global namespace .
header_filename
Path to the corresponding .h.
Path to the corresponding . h .